在 WSDL 中,服务被定义为三个截然不同的部分(服务的地址,组成,绑定):
在 WSDL 中,服务被定义为三个截然不同的部分:
· Port(功能:服务的地址)。Port 定义了可用服务的实际位置(端点)― 例如,SOAP 服务所在的 HTTP URL。
<wsdl:service name="Math">
<wsdl:port name="MathHttpPort" binding="tns:MathHttpBinding">
<wsdlsoap:address location="http://localhost:8080/wsdemo/services/Math"/>
</wsdl:port>
</wsdl:service>
· PortType(功能:服务的组成)。PortType 定义了由服务提供的抽象接口。一个 PortType 定义了一组 Operation。每一个 operation 可能为 In-Out(请求-响应)、In-Only、Out-Only 或 Out-In(恳求-响应)。每一个 operation 定义了 input 和/或 output Message。一个 message 又是被定义为一组 Part,而每一个 part 有一个由模式定义的类型。
<wsdl:portType name="MathPortType">
<wsdl:operation name="Add">
<wsdl:input name="AddRequest" message="tns:AddRequest"/>
<wsdl:output name="AddResponse" message="tns:AddResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:message name="AddResponse">
<wsdl:part name="parameters" element="tns:AddResponse"/>
</wsdl:message>
<wsdl:message name="AddRequest">
<wsdl:part name="parameters" element="tns:Add"/>
</wsdl:message>
· Binding(功能:服务的映射)。一个 binding 定义了如何在一个抽象 PortType 与一个真实的服务格式和协议之间建立映射关系。例如,SOAP 绑定定义了编码风格、SOAPAction 头和 body(targetURI)的名称空间等等。
<wsdl:binding name="MathHttpBinding" type="tns:MathPortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Add">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="AddRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="AddResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
(结束)