术语说明
- WAS6.1 本文特指安装了 Web Service Feature Pack 的 WebSphere Application Server 6.1;
- 客户端本文特指不依赖任何应用服务器或 Web 容器的 Web Service 消费者,运行在 J2SE 单机环境中
WSDL
Web Service 客户端通过服务端的 Web 服务描述语言(WSDL)来获取 Web Service 提供者的接口信息,并且使用这个描述语言来构建客户端的文件。本文使用了如下的 WSDL 来描述服务器端的接口。
清单 1. WSDL
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/Echo/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Echo" targetNamespace="http://www.example.org/Echo/"> <wsdl:types> <xsd:schema targetNamespace="http://www.example.org/Echo/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="requestEcho"> <xsd:complexType> <xsd:sequence> <xsd:element name="req" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="echoHello"> <xsd:complexType> <xsd:sequence> <xsd:element name="resp" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> <wsdl:message name="echoRequestMsg"> <wsdl:part element="tns:requestEcho" name="parameters"/> </wsdl:message> <wsdl:message name="echoHello"> <wsdl:part element="tns:echoHello" name="parameters"/> </wsdl:message> <wsdl:portType name="Echo"> <wsdl:operation name="requestEcho"> <wsdl:input message="tns:echoRequestMsg"/> <wsdl:output message="tns:echoHello"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="EchoSOAP" type="tns:Echo"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="requestEcho"> <soap:operation soapAction="http://www.example.org/Echo/NewOperation"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="Echo"> <wsdl:port binding="tns:EchoSOAP" name="EchoSOAP"> <soap:address location="http://localhost:9095/EchoWeb/Echo"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
|
此服务描述语言描述了服务器端提供了一个回声的 Web Service,它有一个字符串格式的输入参数,返回值也是一个字符串格式的参数。Web Service 的服务地址为 http://localhost:9095/EchoWeb/Echo。
构建过程
本文转自IBM Developerworks中国
请点击此处查看全文