WSDL 端口
WSDL端口技术文档
简介
WSDL(Web Services Description Language)是用于描述Web Services接口的语言。WSDL文件包含了一组描述可用的消息规范,消息传输方式,网络协议以及服务端点等信息的XML元素。而WSDL端口是Web Services中的一个概念,是Web Services体系架构的核心组成部分。
WSDL端口定义了Web Services提供者向 Web Services请求者暴露的服务模板,总的理解就是一个接口。WSDL文件中的每个接口都可以被视为一个N个方法的集合体,这些接口的具体实现是通过Web Services中的“操作”实现的。
端口示例
下面是一个简单的WSDL端口:
<wsdl:definitions name="MyService"
targetNamespace="http://example.org"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.org">
<wsdl:types>
<xsd:schema targetNamespace="http://example.org">
<xsd:element name="AddRequest" type="tns:AddRequestType"/>
<xsd:element name="AddResponse" type="tns:AddResponseType"/>
<xsd:complexType name="AddRequestType">
<xsd:sequence>
<xsd:element name="num1" type="xsd:int"/>
<xsd:element name="num2" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AddResponseType">
<xsd:sequence>
<xsd:element name="result" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="AddRequest">
<wsdl:part name="parameters" element="tns:AddRequest"/>
</wsdl:message>
<wsdl:message name="AddResponse">
<wsdl:part name="parameters" element="tns:AddResponse"/>
</wsdl:message>
<wsdl:portType name="MyServiceInterface">
<wsdl:operation name="Add">
<wsdl:input message="tns:AddRequest"/>
<wsdl:output message="tns:AddResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyServiceSoapBinding" type="tns:MyServiceInterface">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Add">
<soap:operation soapAction="http://example.org/Add"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyService">
<wsdl:port name="MyServiceSoapPort" binding="tns:MyServiceSoapBinding">
<soap:address location="http://example.org/myservice"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
此例子中,WSDL端口的描述如下:
- 端口类型:
<wsdl:portType name="MyServiceInterface">
,包含了本WSDL所有的端口类型定义; - 操作定义:
<wsdl:operation name="Add">
,有如下内容:输入输出消息格式定义、输入输出SOAP绑定头定义; - 服务定义:
<wsdl:service name="MyService">
,包含了服务的所有配置详情; - 端口定义:
<wsdl:port name="MyServiceSoapPort" binding="tns:MyServiceSoapBinding">
,定义了SOAP协议的端点以及绑定; - 消息定义:
<wsdl:message name="AddRequest">
和<wsdl:message name="AddResponse">
分别定义了Add方法调用的输入和输出消息。
端口与绑定
WSDL端口与绑定有关,每个端口都需要与一个具体的绑定关联。绑定可以是SOAP1.1/1.2、HTTP或其他协议。
端口描述了定义WebService的规范,但它并未说明如何与了解这些规范的应用程序进行交互;而绑定描述了如何将WebService端口映射到具体的网络协议和化身。
例如,同上所示的WSDL文件中,绑定定义如下:
<wsdl:binding name="MyServiceSoapBinding" type="tns:MyServiceInterface">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Add">
<soap:operation soapAction="http://example.org/Add"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
绑定名称必须与端口元素名称相同。绑定的类型必须与端口类型相同。
绑定还包含配置详细信息,如SOAP地址和协议。 此信息可用于使用任何Web Service的应用程序。可以将绑定视为WebService端口的化身。