What’s New in WSDL 2.0
原文:http://www.xml.com/pub/a/ws/2004/05/19/wsdl2.html?page=1
by Arulazi Dhesiaseelan
May 20, 2004
W3C 的 Web Services Description Working Group, Web Services Activity 的一个子组织, 已经为描述 web service 定义了一种语言, 也定义了与他们交互的可能方式. The WG 于 26 March 2004 发布了 WSDL 2.0 工作草稿. 这是 WSDL 进化史上的一个重要里程碑. 本文中, 我讨论了相对于 WSDL 1.1 规范所作出的修改以及其它对 web 服务描述语言的主要改进.
W3C WSDL 2.0 工作草稿
W3C 已经公布了下列核心工作草稿作为该工作组交付物一部分:
- Web Services Description Language (WSDL) Version 2.0 Part 1: Core Language
- Web Services Description Language (WSDL) Version 2.0 Part 2: Message Patterns
- Web Services Description Language (WSDL) Version 1.2 Part 3: Bindings
其它相关工作草稿包括需求和使用场景.
W3C XML Schema definition for WSDL 2.0 specification 可见于 http://www.w3.org/2003/11/wsdl/.
The editor’s copies of these documents provide updated information about the progress of these specifications.
Changes from the WSDL 1.1 Specification
WSDL 1.2 重命名为 WSDL 2.0 因为它相对 WSDL 1.1 有很大不同. 这其中的一些改变包括:
- 进一步加强了 WSDL 的语义. 这是在 WSDL 2.0 中要求 targetNamespace 是 definitions element 的一个必需属性的原因之一.
- 去掉了 message 结构.
- 不再支持操作重载.
PortTypes重命名为interfaces. 支持 interface 使用 extends 属性实现继承.Ports重命名为endpoints.
WSDL 2.0 Conceptual Model
一个 web service 的描述可以模型化为两部分. 在抽象部分里, WSDL 通过类型系统描述了 web service 发送和接收的消息, 典型的是使用 W3C XML Schema. Message exchange patterns define the sequence and cardinality of messages. operation 将 message exchange patterns 与一个或多个 messages 关联到一起. interface 在传输和报文中立基础上聚合这些 operations.
在描述的具体部分, bindings 指定了 interfaces 的传输方式和报文格式. service endpoint 将网络地址和 binding 关联在一起. 最后, service 将实现了共同的 interface 的 endpoints 聚合起来. Figure 1 展示了概念性的 WSDL 组件模型.
Figure 1: WSDL Conceptual model
WSDL Components
WSDL 提供了一组组件和它们的属性用于描述 web services. Listing 2 展示了使用 WSDL 2.0 描述的骨架. 下一章节给出每个组件的简要概览.
<definitions targetNamespace="xs:anyURI">
<documentation /> ?
[<import /> | <include /> ] *
<types /> ?
[<interface /> | <binding /> | <service /> ] *
</definitions>
Listing 2: WSDL 2.0 Skeleton
Definitions
definitions element 是 WSDL 文档的根. 它作为一个容器容纳关于 service 及其属性的所有必要信息. Figure 2 展示了 definitions element 的 schema. definitions element 的 targetNamespace 属性是必需的. namespace 能够直接或间接定义 WSDL 的语义. definitions element 也可以有其它可选属性指向其它各种 namespaces, 可用在 WSDL 文档中.
Include
include element 有助于模块化 web service 描述, 这样, 来自同一目标命名空间的各 service 定义组件可存放于不同的 WSDL 文档中, 这非常有利于在多个 web service 描述间使用和共享. location 属性是强制要有的, 用于指定 WSDL 文档的地址. 在被包含 WSDL 中的目标命名空间的实际值必须匹配主(including) WSDL 中 definitions element 的目标命名空间. Figure 3 展示了 include element 的 XML schema.
Import
import element 非常类似于 include element, 除了被 imported WSDL 必须是在不同的 target namespaces. import element 的 namespace attribute 是强制性的, 但 location attribute 是可选的. Figure 4 展示了 import element 的 XML schema.
Types
types element 定义了交换消息使用的数据类型. WSDL 使用 W3C XML Schema 作为首选 schema 语言. 它也支持其它系统如 DTDs and RELAX NG. Schemas 可以在 WSDL 文档的 types element 中进行导入或者嵌入(importing or embedding). 导入是使用 xs:import, 嵌入是使用 xs:schema. 被导入或者嵌入的 schema components 可使用 QName 进行引用. Figure 5 展示了 types element 的 XML schema.
Interface
一个 interface element 封装了一组抽象操作和抽象消息. 它可以(也可以不)继承一个或多个其它 interfaces. Interfaces 在其它组件如 bindings 中使用 QName 进行引用. interface operation element 具有 name 和 pattern 属性, 都是必需的, 但 style 是可选属性. Figure 6 展示了 interface element 的 schema. Features 定义了在通信双方间进行消息交换相关的功能, 这可能包括可靠性, 安全, 相关性, 和路由. Property 用于控制 feature 的行为. It has a set of possible and permissible values specified by references to a schema description. These values can be shared among features.
Binding
binding element 定义了底层传输方式和消息的报文格式. WSDL 中的每个 binding 都引用一个 interface. 所有在该 interface 中定义的 operations 必须在 binding 进行绑定. 在 service 中, endpoint 引用 binding. Both endpoints and bindings are modeled to support flexibility and location transparency. 多个具有不同网络地址的 endpoints 仍可以共享相同协议的 binding. WSDL 2.0 Bindings 规范定义了 binding 协议和消息格式的扩展, 例如 SOAP, HTTP and MIME. Figure 7 展示了 binding element 的 XML schema.
Service
一个 service element 描述一组 endpoints, 每个 endpoint 都为一个 binding 引用一个单一网络地址. 所有其它协议特定信息都包含在 binding. Service 可以使用 QName 进行引用. service element 具有一个 name 和 interface, 都是必需的属性. Figure 8 展示了 service element 的 XML schema.
WSDL Message Exchange Patterns
Message exchange patterns define the sequence and cardinality of messages within an operation. Several types of message patterns are defined in the “Part 2: Message Patterns†of the WSDL 2.0 specifications. WSDL message exchange patterns uses fault generation rules to indicate the occurrence of faults. Message exchange may be terminated if fault generation happens regardless of standard rule sets. The following standard rule set outlines the behavior of fault generation.
- Fault Replaces Messages
- Message Triggers Fault
- No Faults
Figure 9 shows the various message exchange patterns with their fault reference rules.

Figure 9: WSDL Message Exchange Patterns
Stock Quote Service Description in WSDL 1.1 & WSDL 2.0
在这一节, 你可以预览到一个用 WSDL 1.1 和 WSDL 2.0 描述的简单的股票报价服务(stock quote service). Listing 2 展示了用于描述股票报价服务的 XML schema types. Listing 3 and 4 分别展示了用 WSDL 1.1 和 WSDL 2.0 描述的股票报价服务接口定义. Listing 5 and 6 分别展示了 WSDL 1.1 和 WSDL 2.0 的股票报价服务实现的定义.
http://example.com/stockquote/stockquoteV11.xsd
<?xml version="1.0"?>
<schema targetNamespace="http://example.com/stockquote/schemas"
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>
http://example.com/stockquote/stockquoteV20.xsd
<?xml version="1.0"?>
<schema targetNamespace="http://example.com/stockquote/schemas"
xmlns="http://www.w3.org/2001/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>
Listing 2: XML Schema definition for Stock Quote Service
http://example.com/stockquote/stockquoteV11.wsdl
<?xml version="1.0"?>
<definitions name="StockQuote"
targetNamespace="http://example.com/stockquote/definitions"
xmlns:tns="http://example.com/stockquote/definitions"
xmlns:xsd1="http://example.com/stockquote/schemas"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<import namespace="http://example.com/stockquote/schemas"
location="http://example.com/stockquote/stockquoteV11.xsd"/>
<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>
</definitions>
Listing 3: WSDL 1.1 Interface definition for Stock Quote Service
http://example.com/stockquote/stockquoteV20.wsdl
<?xml version="1.0"?>
<definitions name="StockQuote"
targetNamespace="http://example.com/stockquote/definitions"
xmlns:tns="http://example.com/stockquote/definitions"
xmlns:xsd1="http://example.com/stockquote/schemas"
xmlns:soap="http://www.w3.org/2003/11/wsdl/soap12"
xmlns="http://www.w3.org/2003/11/wsdl">
<import namespace="http://example.com/stockquote/schemas"
location="http://example.com/stockquote/stockquoteV20.xsd"/>
<types>
<schema targetNamespace="http://example.com/stockquote/definitions">
<element name="GetLastTradePriceInput" type="xsd1:TradePriceRequest"/>
<element name="GetLastTradePriceOutput" type="xsd1:TradePrice"/>
</schema>
</types>
<interface name="StockQuoteInterface">
<operation name="GetLastTradePrice" pattern="http://www.w3.org/2003/11/wsdl/in-out">
<input message="tns:GetLastTradePriceInput"/>
<output message="tns:GetLastTradePriceOutput"/>
</operation>
</interface>
</definitions>
Listing 4: WSDL 2.0 Interface definition for Stock Quote Service
http://example.com/stockquote/stockquoteserviceV11.wsdl
<?xml version="1.0"?>
<definitions name="StockQuote"
targetNamespace="http://example.com/stockquote/service"
xmlns:tns="http://example.com/stockquote/service"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:defs="http://example.com/stockquote/definitions"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<import namespace="http://example.com/stockquote/definitions"
location="http://example.com/stockquote/stockquoteV11.wsdl"/>
<binding name="StockQuoteSoapBinding" type="defs: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>
Listing 5: WSDL 1.1 Implementation definition for Stock Quote Service
http://example.com/stockquote/stockquoteserviceV20.wsdl
<?xml version="1.0"?>
<definitions name="StockQuote"
targetNamespace="http://example.com/stockquote/service"
xmlns:tns="http://example.com/stockquote/service"
xmlns:wsoap="http://www.w3.org/2003/11/wsdl/soap12"
xmlns:defs="http://example.com/stockquote/definitions"
xmlns="http://www.w3.org/2003/11/wsdl">
<import namespace="http://example.com/stockquote/definitions"
location="http://example.com/stockquote/stockquoteV12.wsdl"/>
<binding name="StockQuoteSoapBinding" interface="defs:StockQuoteInterface">
<wsoap:binding protocol="http://www.w3.org/2003/11/wsdl/http"/>
<operation name="GetLastTradePrice">
<wsoap:operation soapAction="http://example.com/GetLastTradePrice"/>
<input>
<wsoap:body/>
</input>
<output>
<wsoap:body/>
</output>
</operation>
</binding>
<service name="StockQuoteService">
<documentation>My stock quote service</documentation>
<endpoint name="StockQuoteEndPoint" binding="tns:StockQuoteSoapBinding">
<wsoap:address location="http://example.com/stockquote"/>
</endpoint>
</service>
</definitions>
Listing 6: WSDL 2.0 Implementation definition for Stock Quote Service
Summary
在本文中, 我解释了 WSDL 2.0 规范的工作草稿的一些详细情况. 该工作组正在讨论是否向现有规范中增加更多的特性以便提供高度灵活性和强壮的语言来描述 web services. 这些特性包括 web service 引用(references), 版本化(versioning), 属性(attributes), 和 compositors. 除了这些新特性, further refinements are made to the existing specification. 开发者社区希望在不久的将来能有一个更稳定的 WSDL 2.0 规范的版本.
Categorized in: SOA · Tagged with: schema, SOAP, WSDL, XML










(