WSDL UDDI 学习笔记
什么是 WSDL?
Web Services Description Language (WSDL) 是一种 XML 文件,用于描述 Web 服务的交互方式。它定义了 Web 服务中可用的操作、输入和输出参数之间的关系,以及如何进行通信。
WSDL 使用 XML Schema 语言来描述消息和数据结构。这样,客户端就可以理解要传递给 Web 服务的数据,以及期望从 Web 服务接收的数据格式。
以下是一个简单的 WSDL 示例:
xmlCopy Code<definitions name="ServiceName" targetNamespace="http://www.example.com/ServiceName">
<types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/ServiceName">
<xsd:element name="AddRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="a" type="xsd:int"/>
<xsd:element name="b" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AddResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<message name="AddRequestMessage">
<part name="parameters" element="tns:AddRequest"/>
</message>
<message name="AddResponseMessage">
<part name="parameters" element="tns:AddResponse"/>
</message>
<portType name="ServiceNamePortType">
<operation name="Add">
<input message="tns:AddRequestMessage"/>
<output message="tns:AddResponseMessage"/>
</operation>
</portType>
<binding name="ServiceNameBinding" type="tns:ServiceNamePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Add">
<soap:operation soapAction="http://www.example.com/ServiceName/Add"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ServiceName">
<port name="ServiceNamePort" binding="tns:ServiceNameBinding">
<soap:address location="http://www.example.com/ServiceName"/>
</port>
</service>
</definitions>
注意,该示例仅包含一个操作。WSDL 文件可以定义多个操作和服务。
什么是 UDDI?
Universal Description, Discovery, and Integration (UDDI) 是一种 Web 服务注册表,用于描述 Web 服务及其位置。使用 UDDI 可以轻松地找到可供使用的 Web 服务,并了解如何与这些服务进行交互。
以下是 UDDI 的一个示例:
xmlCopy Code<businessList>
<businessInfo businessKey="uuid:4a6f3e18-2047-11e9-9228-000c296c12b4" description="This is a sample business." name="Sample Business">
<serviceInfos>
<serviceInfo serviceKey="uuid:4a6f3e18-2047-11e9-9228-000c296c12b4" businessKey="uuid:4a6f3e18-2047-11e9-9228-000c296c12b4">
<serviceDetail>
<description>This is a sample service.</description>
<bindingTemplates>
<bindingTemplate bindingKey="uuid:4a6f3e18-2047-11e9-9228-000c296c12b4">
<accessPoint useType="endPoint">http://www.example.com/SampleService</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey="uddi:uddi.org:xml:SOAPBinding">
<instanceDetails>
<instanceParms>
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
</instanceParms>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
</bindingTemplates>
</serviceDetail>
</serviceInfo>
</serviceInfos>
</businessInfo>
</businessList>
该示例定义了一个 UDDI 描述文件,其中包含一个业务 (Business) 和一个服务 (Service)。还有一个绑定模板 (Binding Template),定义了如何访问该服务的细节。
WSDL 和 UDDI 如何一起工作?
WSDL 和 UDDI 可以一起使用,以简化 Web 服务的查找和使用过程。
UDDI 提供了一个 Web 服务注册表,可以将 Web 服务信息存储在其中。WSDL 则提供了一种描述 Web 服务的方式。使用 UDDI 中存储的 Web 服务信息,可以生成 WSDL 文档。
举个例子,假设有一个名为 "Sample Service" 的 Web 服务,它已经注册到 UDDI 中。客户端应用程序可以查找 UDDI,找到 Sample Service 的注册信息,并获取其 WSDL 文档。然后,客户端就可以使用 WSDL 文档中提供的信息来构建 SOAP 消息,与该 Web 服务进行交互。
总之,WSDL 和 UDDI 的结合,使得发现和使用 Web 服务变得更加容易。