WSDL是web service标准当中描述语言,服务器端通过wsdl可以描述发布的服务,客户端通过获取服务端提供的wsdl了解服务器端,以便调用服务器端提供的服务。
元素 | 定义 |
<portType> | web service 执行的操作 |
<message> | web service 使用的消息 |
<types> | web service 使用的数据类型 |
<binding> | web service 使用的通信协议 |
<service> | web service 使用的服务名称和地址 |
下面分段了解一下wsdl的详细描述吧。我们通过一个搜索方法来描述,该方法提供输入搜索字段和搜索关键字,分别是String类型的。返回结果是一个结果集,用List类型保存。我们按照上面的表格来一个个的分析下WSDL的构成。
<service>元素描述
<wsdl:service name="SimpleSearch_Server"> <wsdl:port name="SimpleSearch_ServerHttpPort" binding="tns:SimpleSearch_ServerHttpBinding"> <wsdlsoap:address location="http://localhost:8080/Patent_Demo/services/SimpleSearch_Server" /> </wsdl:port> </wsdl:service>
1. 申明该服务的名称是SimpleSearch_Server
2. Binding表示需要绑定的通信协议是什么,绑定到wsdl当中的binding元素,这里指定到SimpleSearch_ServerHttpBinding当中。
3. 申明提供的服务地址是:
http://localhost:8080/Patent_Demo/services/SimpleSearch_Server通过访问
http://localhost:8080/Patent_Demo/services/SimpleSearch_Server?wsdl可以查看wsdl信息
<binding>元素描述
<wsdl:binding name="SimpleSearch_ServerHttpBinding" type="tns:SimpleSearch_ServerPortType"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="search"> <wsdlsoap:operation soapAction="" /> <wsdl:input name="searchRequest"> <wsdlsoap:body use="literal" /> </wsdl:input> <wsdl:output name="searchResponse"> <wsdlsoap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding>1. 申明该 binding 名称是 SimpleSearch_ServerHttpBinding
2. 指定该binding指定的操作元素为tns:SimpleSearch_ServerPortType
3. 该服务提供search方法,并具有request-response模式。消息传递类型为literal
<Port-type>元素描述
<wsdl:portType name="SimpleSearch_ServerPortType"> <wsdl:operation name="search"> <wsdl:input name="searchRequest" message="tns:searchRequest" /> <wsdl:output name="searchResponse" message="tns:searchResponse" /> </wsdl:operation> </wsdl:portType>1. 定义提供 search 方法
2. 定义request-response模式,并制定消息类型为searchRequest和searchResponse
<message>元素描述
<wsdl:message name="searchResponse"> <wsdl:part name="parameters" element="tns:searchResponse" /> </wsdl:message> <wsdl:message name="searchRequest"> <wsdl:part name="parameters" element="tns:search" /> </wsdl:message>1. 对应 port-type 当中的消息类型,以 searchResponse 为例,当用户发送请求的时候,定义请求参数类型为 search
2. searchResponse当中定义了当请求处理完毕向用户返回参数的类型为searchResponse。两者都对应到<type>元素当中
<type>元素描述
<wsdl:types>
<wsdl:types> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.ws.patent.com"> <xsd:element name="search"> <xsd:complexType> <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" /> <xsd:element maxOccurs="1" minOccurs="1" name="in1" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:complexType name="ArrayOfString"> <xsd:sequence> <xsd:element maxOccurs="unbounded" minOccurs="0" name="string" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> <xsd:element name="searchResponse"> <xsd:complexType> <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="tns:ArrayOfString" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types>1. search 类型对应 message 消息当中请求消息类型, searchResponse 同样如此。
2. search当中定义请求的第0,1个参数分别用String类型表示
3. searchResponse中定义返回以几何形式(ArrayofString)类型。ArrayofString在type元素当中也有定义,表示由String组成的类型组成
回去吃饭洛