1.什么是 SOAP、 WSDL?
SOAP : SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息的简
单的协议,是一个基于XML的协议
WSDL : WSDL(Web Service Description Language)就是描述XML Web服务的标准XML格式。
2.WSDL文档结构
WSDL文档可以分为两部分。顶部分由抽象定义组成,而底部分则由具体描述组成。
2.1 抽象定义
Types : 独立与机器和语言的类型定义
Messages : 包括函数参数(输入与输出分开)或文档描述
PortTypes : 引用消息部分中消息定义来描述函数签名(操作名、输入参数、输出参数)
2.2 具体定义
Bindings : PortTypes部分的每一操作在此绑定实现
Services : 确定每一绑定的端口地址
注意,文档之中可能只有一个Types栏,或根本没有。所有其他的栏可以只有零元素、单元素或是多元素。
WSDL的列表要求所有的栏以固定的顺序出 现:import, types, message, portType, binding, service。
所有的抽象可以是单独存在于别的文件中,也可以从主文档中导入。
2.3 WSDL文件示例
<?xml version="1.0"?> <definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl" xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2000/10/XMLSchema"> <element name="TradePriceRequest"> <complexType> <all> <element name="tickerSymbol" type="string"/> </all> </complexType> </element> <element name="TradePrice"> <complexType> <all> <element name="price" type="float"/> </all> </complexType> </element> </schema> </types> <message name="GetLastTradePriceInput"> <part name="body" element="xsd1:TradePriceRequest"/> </message> <message name="GetLastTradePriceOutput"> <part name="body" element="xsd1:TradePrice"/> </message> <portType name="StockQuotePortType"> <operation name="GetLastTradePrice"> <input message="tns:GetLastTradePriceInput"/> <output message="tns:GetLastTradePriceOutput"/> </operation> </portType> <binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="GetLastTradePrice"> <soap:operation soapAction="http://example.com/GetLastTradePrice"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="StockQuoteService"> <documentation>My first service</documentation> <port name="StockQuotePort" binding="tns:StockQuoteBinding"> <soap:address location="http://example.com/stockquote"/> </port> </service> </definitions>
2.3.1 各部分含义:
(1) <definitions> 部分 : 文档各名称空间声明.URI 字符串的值对于 XML 和 XSL 处理器一点不重要,但它必须是唯一的。
(2) <types>部分 : 各类型声明。 其中对于复杂类型的,一般使用<all>或<sequence>来限定其类型出现的次序和次数。若用<all> 则限定子元素能够以任意顺序出现,每个子元素可出现零次或一次。若用<sequence> 则要求子元素必须按顺序出现。每个子元素可出现 0 到任意次数。
(3) <message>部分 :输入及输出消息;
(4) <portType>和<operation>元素 : PortType定义了一些抽象的操作。PortType中的operation元素定义了调用PortType中所有方法的语法,每一个 operation元素声明了方法的名称、参数(使用<message>元素)和各自的类型(<part>元素要在所有<message>中声明)。
(5) <binding>和<operation>元素 : Binding栏是完整描述协议、序列化和编码的地方,Types, Messages和PortType栏处理抽象的数据内容,而Binding栏是处理数据传输的物理实现。Binding栏把前三部分的抽象定义具体化。
(6) <service>和<port>元素 : service是一套<port>元素。在一一对应形式下,每个<port>元素都和一个location关联。如果同一个<binding>有多个<port>元素与之关联,可以使用额外的URL地址作为替换。