![](https://images2017.cnblogs.com/blog/632932/201708/632932-20170823142443105-1733702756.png)
WSDL 端口
<portType> 元素是最重要的 WSDL 元素。
它可描述一个 web service、可被执行的操作,以及相关的消息。
可以把 <portType> 元素比作传统编程语言中的一个函数库(或一个模块、或一个类)。
WSDL 消息
<message> 元素定义一个操作的数据元素。
每个消息均由一个或多个部件组成。可以把这些部件比作传统编程语言中一个函数调用的参数。
WSDL types
<types> 元素定义 web service 使用的数据类型。
为了最大程度的平台中立性,WSDL 使用 XML Schema 语法来定义数据类型。
WSDL Bindings
<binding> 元素为每个端口定义消息格式和协议细节。
![](https://images2017.cnblogs.com/blog/632932/201708/632932-20170823142512386-600701340.png)
<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
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>
<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
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>
上述为:绑定到 SOAP一个 请求 - 响应 操作的例子:其中
binding 元素有两个属性 - name 属性和 type 属性。
name 属性定义 binding 的名称,而 type 属性指向用于 binding 的端口,在这个例子中是 "glossaryTerms" 端口。
soap:binding 元素有两个属性 - style 属性和 transport 属性。
style 属性可取值 "rpc" 或 "document"。在这个例子中我们使用 document。transport 属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP。
operation 元素定义了每个端口提供的操作符。
对于每个操作,相应的 SOAP 行为都需要被定义。同时您必须如何对输入和输出进行编码。在这个例子中我们使用了 "literal"。
一个完整的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>
<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>