WSDL是一种描述网络服务(network service)的XML格式,网络服务是能对面向文档类型的信息和面向过程的信息进行操作的端点(endpoint)的集合。对操作和消息的描述是抽象性的,并在定义端点时,将消息和操作绑定到具体的网络协议和消息格式上。WSDL是可扩展的,它允许对端点和端点间的消息进行描述,同时不去考虑具体的消息格式或者双方用于通讯的网络协议。

 

 

 

一 简介

 

随着通讯协议和消息格式在WEB中的标准化,以某种格式化的方法描述通讯变得越来越重要并且其实现的可能性也越来越大。WSDL通过定义一套XML的语法来描述网络服务的方式满足了这种需求。WSDL把网络服务定义成一个能交换消息的通讯端点集(communication collection)。WSDL服务为分布式系统提供了帮助文档,同时该服务也可作为自动实现应用间通讯的解决方案。

 

 

 

一个WSDL文档将服务定义为一个网络端点的集合,或者说端口的集合。在WSDL里面,端点及消息的抽象定义与它们具体的网络实现和数据格式绑定是分离的。这样就可以重用这些抽象定义:消息,需要交换的数据的抽象描述;端口类型,操作的抽象集合。针对一个特定端口类型的具体协议和数据格式规范构成一个可重用的绑定。一个端口定义成网络地址和可重用的绑定的联接,端口的集合定义为服务。因此一个WSDL文档在定义网络服务的时候使用如下的元素:

 

 

 

类型使用某种的类型系统(比如XSD)定义数据类型的容器

 

消息通讯数据抽象的有类型的定义

 

操作服务支持的动作的抽象描述

 

端口类型一个操作的抽象集合,该操作由一个或多个端点支持

 

绑定针对一个特定端口类型的具体的协议规范和数据格式规范

 

端口一个单一的端点,定义成一个绑定和一个网络地址的联接

 

服务相关的端点的集合

 

我们可以注意到WSDL并没有引入一种新的类型语言,这一点非常重要。为了描述消息的结构,需要具有丰富类型的系统,WSDL意识到了这种需求,因此它支持XMLschema规范作为它的规范的类型系统。但是仅使用一种类型语言来描述现在和将来的所有消息格式显然是不可能的,因此WSDL可以扩展使用其他的类型定义语言。

 

WSDL文档实例

 

以下的实例是一个用WSDL定义的简单的股票价格咨询服务。服务支持唯一一个操作称为GetLastTradePrice,该服务使用基于HTTPSOAP协议来实现。请求带有一个字符串类型的交易标记(ticker symbol),同时返回一个浮点数类型的价格。

 

 

 

范例:通过HTTP实现的SOAP 1.1 Request/Response

 

 

 

<?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/1999/XMLSchema">

 

<element name="TradePriceRequest">

 

<complexType>

 

<all>

 

<element name="tickerSymbol" type="string"/>

 

</all>

 

</complexType>

 

</element>

 

<element name="TradePriceResult">

 

<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:TradePriceResult"/>

 

</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" namespace="http://example.com/stockquote.xsd"

 

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

 

</input>

 

<output>

 

<soap:body use="literal" namespace="http://example.com/stockquote.xsd"

 

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

 

</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>

 

SOAP绑定

 

WSDL包括对SOAP1.1端点的绑定,它支持对与协议相关的信息作如下的设定:

 

 

 

表明绑定到SOAP1.1的标记

 

SOAP端点指定地址

 

SOAP绑定到HTTP时需要指定SOAPAction HTTP头,该头是一个URI类型的值

 

SOAP头的定义列表,该SOAP头将转化为SOAP封装(SOAP Envelope

 

一个在XSD中指定SOAP根的方式

 

 

 

这里的绑定语法并不是一个最终的规范,因为SOAP绑定集还处在发展之中。

 

 

 

SOAP 范例

 

在下列例子中,一个 SubscribeToQuotes SOAP 1.1单向(one-way)消息通过SMTP绑定发送到StockQuote服务中。请求带一个字符串类型的交易标记,同时还包括一个头,该头定义了发送者的URI

 

 

 

范例:在SMTP之上的单向(one-way)操作的SOAP绑定,使用SOAP

 

 

 

<?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/">

 

 

 

<message name="SubscribeToQuotes">

 

<part name="body" element="xsd1:SubscribeToQuotes"/>

 

</message>

 

 

 

<portType name="StockQuotePortType">

 

<operation name="SubscribeToQuotes">

 

<input message="tns:SubscribeToQuotes"/>

 

</operation>

 

</portType>

 

 

 

<binding name="StockQuoteSoap" type="tns:StockQuotePortType">

 

<soap:binding style="document" transport="http://example.com/smtp"/>

 

<operation name="SubscribeToQuotes">

 

<input message="tns:SubscribeToQuotes">

 

<soap:header element="xsd1:SubscriptionHeader"/>

 

</input>

 

</operation>

 

</binding>

 

 

 

<service name="StockQuoteService">

 

<port name="StockQuotePort" binding="tns:StockQuoteSoap">

 

<soap:address location="mailto://subscribe@example.com"/>

 

</port>

 

</service>

 

 

 

<types>

 

<schema targetNamespace="http://example.com/stockquote.xsd"

 

xmlns="http://www.w3.org/1999/XMLSchema">

 

<element name="SubscribeToQuotes">

 

<complexType>

 

<all>

 

<element name="tickerSymbol" type="string"/>

 

</all>

 

</complexType>

 

</element>

 

<element name="SubscriptionHeader" type="uriReference"/>

 

</schema>

 

</types>

 

</definitions>

 

 

 

这个例子描述了一个 GetLastTradePrice SOAP 1.1 请求,该请求可能通过SOAP 1.1 HTTP绑定发送到StockQuote服务。请求带一个字符串类型交易标记,一个时间实例(timeInstant)类型的时间,请求在SOAP应答中返回一个浮点数的价格。

 

四 有关SOAP 2.0

 

微软将推出新版SOAP 2.0〔简易对象存取协议〕的套件,还表示操作系统Windows XP将支持这一协议。

 

  

 

SOAP 2.0整合了网络服务描述式语言WSDL,使用Visual Studio 6.0的程序开发者可凭借SOAP套件来撰写SOAPXML兼容的应用程序,并在现有COM应用程序中加入这些功能。除微软外,SilverStreamCape Clear两家公司也表示,它们的J2EE应用程序服务器也将支持SOAP

 

  

 

尽管SOAP已引起业界瞩目﹐但它仍需大量相关企业的支持。但问题是,SOAP还未成熟,还需增加更多功能,如安全防护,而且业界也没有放弃旧有成熟标准的必要。