W3C WSDL 活动学习笔记
什么是WSDL?
WSDL(Web Services Description Language)是一种XML格式的语言,用于描述网络服务的公开接口。它定义了服务的位置、操作以及可用参数/数据类型等信息。
WSDL的结构
WSDL文档由四个主要部分构成:
- 定义服务:描述服务的名称、命名空间和端点等信息。
- 定义数据类型:定义用于传输数据的自定义数据类型。
- 定义消息:描述在操作过程中使用的单个消息。
- 定义操作:描述服务可以执行的操作及其输入输出参数。
WSDL实例
下面是一个简单的WSDL文件实例,它定义了一个用于转换货币的Web服务:
Copy Code<?xml version="1.0" encoding="UTF-8"?>
<definitions name="CurrencyConverter"
targetNamespace="http://www.example.org/CurrencyConverter/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.example.org/CurrencyConverter/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
<types>
<xsd:schema targetNamespace="http://www.example.org/CurrencyConverter/">
<xsd:element name="USD" type="xsd:decimal"/>
<xsd:element name="EUR" type="xsd:decimal"/>
<xsd:element name="ConversionRate" type="xsd:decimal"/>
</xsd:schema>
</types>
<message name="GetConversionRateInput">
<part name="FromCurrency" type="tns:USD"/>
<part name="ToCurrency" type="tns:EUR"/>
</message>
<message name="GetConversionRateOutput">
<part name="Rate" type="tns:ConversionRate"/>
</message>
<portType name="CurrencyConverterPortType">
<operation name="GetConversionRate">
<input message="tns:GetConversionRateInput"/>
<output message="tns:GetConversionRateOutput"/>
</operation>
</portType>
<binding name="CurrencyConverterBinding" type="tns:CurrencyConverterPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetConversionRate">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="CurrencyConverterService">
<port name="CurrencyConverterPort" binding="tns:CurrencyConverterBinding">
<soap:address location="http://www.example.org/CurrencyConverter/"/>
</port>
</service>
</definitions>
在上面的例子中,我们定义了以下内容:
- 服务名称:CurrencyConverter
- 命名空间:http://www.example.org/CurrencyConverter/
- 端点地址:http://www.example.org/CurrencyConverter/
- 输入参数:FromCurrency (USD),ToCurrency (EUR)
- 输出参数:Rate (ConversionRate)