webService--wsdl查看
WebService顾名思义就是web服务,web服务主要有两种,一种是基于soap类型的服务,一种是基于rest类型的服务,
其中soap类型的服务有两种版本,一种是soap1.1版本,一种是soap1.2版本,soap服务类型的数据是xml数据格式的,
rest服务的数据类型是json格式的
wsdl查看是从下往上的
根据wsdl写客户端
HelloWorldService hws = new HelloWorldService; //service的name
HelloWorld hw = hws.getHelloWorld()//service下port的name
String s1 = hw.sayHelloWorldFrom("lhw");
1.wsdl:service
<wsdl:service name="HelloWorldService"> <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld"> <wsdlsoap:address location="http://localhost:8080//services/example/HelloWorld"/> </wsdl:port> </wsdl:service>
wsdl:service 是表明这个服务的名称:HelloWorldService 服务的地址:http://localhost:8080//services/example/HelloWorld
service的binding绑定了 2.wsdl:binding 的name
2.wsdl:binding
简单代码说明:
<wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld"> </wsdl:binding>
详细代码:
<wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="sayHelloToYou"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="sayHelloToYouRequest"> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output name="sayHelloToYouResponse"> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="sayHelloWorldFrom"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="sayHelloWorldFromRequest"> <wsdlsoap:body use="literal"/> </wsdl:input> <wsdl:output name="sayHelloWorldFromResponse"> <wsdlsoap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding>
binding的type 是3wsdl:portType的的name
3.wsdl:portType
<wsdl:portType name="HelloWorld"> <wsdl:operation name="sayHelloToYou" parameterOrder="name sex address"> <wsdl:input message="impl:sayHelloToYouRequest" name="sayHelloToYouRequest"/> <wsdl:output message="impl:sayHelloToYouResponse" name="sayHelloToYouResponse"/> </wsdl:operation> <wsdl:operation name="sayHelloWorldFrom" parameterOrder="from"> <wsdl:input message="impl:sayHelloWorldFromRequest" name="sayHelloWorldFromRequest"/> <wsdl:output message="impl:sayHelloWorldFromResponse" name="sayHelloWorldFromResponse"/> </wsdl:operation> </wsdl:portType>
wsdl:operation的name即代表着是接口名称
parameterOrder代表着参数名称
四个message对应wsdl:message的name
4.wsdl:message
<wsdl:message name="sayHelloWorldFromResponse"> <wsdl:part element="impl:sayHelloWorldFromReturn" name="sayHelloWorldFromReturn"/> </wsdl:message> <wsdl:message name="sayHelloToYouResponse"> <wsdl:part element="impl:sayHelloToYouReturn" name="sayHelloToYouReturn"/> </wsdl:message> <wsdl:message name="sayHelloWorldFromRequest"> <wsdl:part element="impl:from" name="from"/> </wsdl:message> <wsdl:message name="sayHelloToYouRequest"> <wsdl:part element="impl:name" name="name"/> <wsdl:part element="impl:sex" name="sex"/> <wsdl:part element="impl:address" name="address"/> </wsdl:message>
wsdl:part对应wsdl:types的name
5.wsdl:types(在服务正式发布后的wsdl中,无具体的element节点)
<wsdl:types> <schema elementFormDefault="qualified" targetNamespace="http://example" xmlns="http://www.w3.org/2001/XMLSchema"> <element name="name" type="xsd:string"/> <element name="sex" type="xsd:string"/> <element name="address" type="xsd:string"/> <element name="sayHelloToYouReturn" type="xsd:string"/> <element name="from" type="xsd:string"/> <element name="sayHelloWorldFromReturn" type="xsd:string"/> </schema> </wsdl:types>
最终在每个element的type处 就可以知道每个参数和返回值的类型