WSDL 学习笔记
一. 学习资料参考
http://www.w3school.com.cn/wsdl/index.asp
二. WSDL 的定义
WSDL ( Web Services Description Language )全名为网络服务描述语言,他是 W3C 组织于 2002 年 7 月发布的一项用于描述 web 服务的文档,此文档用 XML 语言编写,体现其跨平台性。其文档主要描述了 web 服务所提供的操作(或方法)。
三 .WSDL 的文档结构:
WSDL 用以下元素来描述某个 web service:
元素 | 定义 |
<portType> | Web service 执行的操作 |
<message> | Web service 使用的消息 |
<types> | Web service 使用的数据类型 |
<binding> | Web service 使用的协议 |
文档格式如下:
<definitions>
<types>
definition of types........
</types>
<message>
definition of a message....
</message>
<portType>
definition of a port.......
</portType>
<binding>
definition of a binding....
</binding>
</definitions>
WSDL 还包含其他元素比如extension 元素,此元素可把若干个web service 的定义组合在一个单一的WSDL 文档中。
<porttype>:WSDL 端口
Porttype 相当于编程里面的函数库(或一个模块、或一个类)。
<message>:WSDL 消息元素定义一个操作的数据元素。
每个消息均有一个或多个部件组成,可以吧消息比作编程语言中函数调用的参数。
<types> 定义元素的数据类型,为了最大程度的平台中立性, WSDL 使用 XML schema 语法来定义数据类型。
<binding> 元素为每个端口定义消息格式和协议细节。
四. WSDL 文档的请求 -- 响应操作
在 WSDL 中支持 4 中不同类型的响应方式,分别为
类型 | 定义 |
One-way | 此操作可接受一个消息,但不会返回响应 |
Requesrt-Respose | 此操作可以接受一个请求,并返回一个响应 |
Solicit-responses | 发送一个消息,并且等待响应 |
Notification | 发送一个请求,单不会等待响应 |
One-way 的实现
<message name=”newTermValues”>
<part name=”term” type=”xs:string”/>
<part name=”value” type=”xs:string”/>
</message>
<portType name=”glossaryTerms”>
<operation name=”setTerm”>
<input name=”newTerm” message=”newTermValues”/>
</operation>
</portType>
Request-Respose 的实现:
<message name=”newTermValues”>
<part name=”requestParamter” type=”sx:string”>
</message>
<message name=”newTermValues”>
<part name=” reposeParamter” type=”sx:string”>
</message>
<portType name=”glossaryTerms”>
<operation name=”setTerm”>
<input message=” requestParameter”/>
<output messge=”resposeParameter”/>
</operation>
</porType>
五. 绑定 SOAP 协议
绑定到 SOAP
一个 请求 - 响应 操作的例子:
<message name="getTermRequest">
<part name="term" type="xs:string" />
</message>
<message name="getTermResponse">
<part name="value" type="xs:string" />
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest" />
<output message="getTermResponse" />
</operation>
</portType>
<binding type="glossaryTerms" name="b1">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation>
<soap:operation
soapAction="http://example.com/getTerm" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
binding 元素有两个属性 - name 属性和 type 属性。
name 属性定义 binding 的名称,而 type 属性指向用于 binding 的端口,在这个例子中是 "glossaryTerms" 端口。
soap:binding 元素有两个属性 - style 属性和 transport 属性。
style 属性可取值 "rpc" 或 "document" 。在这个例子中我们使用 document 。 transport 属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP 。
operation 元素定义了每个端口提供的操作符。
对于每个操作,相应的 SOAP 行为都需要被定义。同时您必须如何对输入和输出进行编码。在这个例子中我们使用了 "literal" 。
六: UDDI 和 WSDL
UDDI 是一种目录服务,企业可以使用它对 Web services 进行注册和搜索。
UDDI 英文为“ Universal Description,Discovery and Integration ”翻译为通用描述、发现与集成服务。
UDDI 规范帮助我们解决的问题:
1. 能利用 inerter 网在数以百计的 web service 服务中得到你想要的那个服务。
2. 一旦找到你期望那个服务后,可以使用服务当中具体的内容。
3. 使用 UDDI 可以扩展 web service 服务,能获取更多的使用者。
4. 使用 UDDI 可以更好整合各个系统,可以进行更统一的维护和管理。
七: WSDL 语法
<wsdl:definitions name="nmtoken"? targetNamespace="uri">
<import namespace="uri" location="uri"/> *
<wsdl:documentation .... /> ?
<wsdl:types> ?
<wsdl:documentation .... /> ?
<xsd:schema .... /> *
</wsdl:types>
<wsdl:message name="ncname"> *
<wsdl:documentation .... /> ?
<part name="ncname" element="qname"? type="qname"?/> *
</wsdl:message>
<wsdl:portType name="ncname"> *
<wsdl:documentation .... /> ?
<wsdl:operation name="ncname"> *
<wsdl:documentation .... /> ?
<wsdl:input message="qname"> ?
<wsdl:documentation .... /> ?
</wsdl:input>
<wsdl:output message="qname"> ?
<wsdl:documentation .... /> ?
</wsdl:output>
<wsdl:fault name="ncname" message="qname"> *
<wsdl:documentation .... /> ?
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:serviceType name="ncname"> *
<wsdl:portType name="qname"/> +
</wsdl:serviceType>
<wsdl:binding name="ncname" type="qname"> *
<wsdl:documentation .... /> ?
<-- binding details --> *
<wsdl:operation name="ncname"> *
<wsdl:documentation .... /> ?
<-- binding details --> *
<wsdl:input> ?
<wsdl:documentation .... /> ?
<-- binding details -->
</wsdl:input>
<wsdl:output> ?
<wsdl:documentation .... /> ?
<-- binding details --> *
</wsdl:output>
<wsdl:fault name="ncname"> *
<wsdl:documentation .... /> ?
<-- binding details --> *
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ncname" serviceType="qname"> *
<wsdl:documentation .... /> ?
<wsdl:port name="ncname" binding="qname"> *
<wsdl:documentation .... /> ?
<-- address details -->
</wsdl:port>
</wsdl:service>
</wsdl:definitions>