一、简介
WSDL 是基于 XML 的用于描述 Web Services 以及如何访问 Web Services 的语言,可规定服务的位置,以及此服务提供的操作(或方法)
WSDL 指网络服务描述语言
WSDL 使用 XML 编写
WSDL 用于描述网络服务,也可用于定位网络服务
WSDL 还不是 W3C 标准
二、WSDL文档结构
1)、<portType>:描述由某个 web service 提供的合法操作,端口定义了指向某个 web service 的连接点,可以把该元素比作传统编程语言中的一个函数库(或一个模块、
或一个类),而把每个操作比作传统编程语言中的一个函数,可把 <portType> 元素比作传统编程语言中的一个函数库,其操作类型:
a)、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 >
b)、Request-response:此操作可接受一个请求并会返回一个响应
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<!-- 把 "glossaryTerms" 定义为某个端口的名称,把 "getTerm" 定义为某个操作的名称,操作 "getTerm" 拥有一个名为 "getTermRequest" 的输入消息,
以及一个名为 "getTermResponse" 的输出消息 -->
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
c)、Solicit-response:此操作可发送一个请求,并会等待一个响应
d)、Notification:此操作可发送一条消息,但不会等待响应
2)、<message>:web service 使用的消息,可以把这些部件比作传统编程语言中一个函数调用的参数
3)、<types>:web service 使用的数据类型,为了最大程度的平台中立性,WSDL 使用 XML Schema 语法来定义数据类型
4)、<binding>:web service 使用的通信协议,为 web service 定义消息格式和协议细节
<!-- name:定义 binding 的名称,type:指向用于 binding 的端口 -->
<binding type="glossaryTerms" name="b1">
<!-- style:可取值 "rpc" 或 "document",transport:定义了要使用的 SOAP 协议,例子使用 HTTP -->
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<!-- operation 元素定义了每个端口提供的操作符,对于每个操作,相应的 SOAP 行为都需要被定义,且必须如何对输入和输出进行编码,例子使用了 "literal" -->
<operation>
<soap:operation soapAction="http://example.com/getTerm" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
实例:
<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>