1 / 60

Web 服务描述语言 WSDL

Web 服务描述语言 WSDL. 马殿富 北航计算机学院 200 6-05. 主要内容. WSDL 发展历史 WSDL 的基本属性 WSDL 的定义 WSDL 的文档框架 --类型 消息 端口类型 绑定 服务 WSDL 中的 4 种消息交换方式 WSDL 中的 4 种消息传递模式. 发展历史. Web 服务描述语言 WSDL ( Web Services Description Language )是一个建议性标准。用于描述 Webb 服务的技术调用语法。

Download Presentation

Web 服务描述语言 WSDL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web服务描述语言WSDL 马殿富 北航计算机学院 2006-05

  2. 主要内容 • WSDL发展历史 • WSDL的基本属性 • WSDL的定义 • WSDL的文档框架 • --类型 消息 端口类型 绑定 服务 • WSDL中的4种消息交换方式 • WSDL中的4种消息传递模式

  3. 发展历史 • Web服务描述语言WSDL(Web Services Description Language)是一个建议性标准。用于描述Webb服务的技术调用语法。 • 1999年HP(惠普)公司是第一个引入Web服务概念,eSpeak实现了“电子服务”平台。 • 2000年6月Microsoft提出了“Web服务”术语,把Web服务作为.NET计划重要组件。 • 在Microsoft的SDL(Service Description Language和SCL(SOAP Contract Language)和IBM的NASSL(Network Accessible Service Specification Language)这两项技术的结合,形成了WSDL的基础。SCL采用XML来描述应用程序所交换的消息,NASSL描述服务接口和实现细节。 • 2000年9月25日IBM、Microsoft和Ariba提出WSDL1.0。2001年3月15日,他们提交的WSDL1.1成为W3C的Note。WSDL1.1规范网址是http://www.w3.org/TR/wsdl。2002年7月9日提出WSDL1.2,2003年11月10日提出WSDL2.0。

  4. WSDL描述web服务的三个基本属性: • 服务做些什么? • 服务所提供的操作(方法); • 如何访问服务? • 数据格式以及访问服务操作的必要协议; • 服务位于何处? • 由特定协议决定的网络地址,如URL。

  5. Web服务描述语言(Web Services Description Language WSDL)是Web Services技术重要组成部分。 • WSDL描述了分布在Internet环境中服务操作的抽象定义接口和服务的具体实现端口,实现远程计算资源共享。 • WSDL通常是协议定义的,协议描述缺乏准确性和严格性,需要一种形式化的表示和描述方法。

  6. 面向服务视图 WSDL2JAVA JAVA2WSDL • 规范描述资源与协议变换 • 实现自动服务部署和调用 UDDI 客户端(人) 发布 发现与定位 Content 发现与定位 浏览器AJAX 运行时 操作 客户端(机器) 服务 资源

  7. SOAP RPC • SOAP文档内容 • <soap:envelope> • <soap:body> • <myMethod> • <x>5</x> • </myMethod> • </soap:body> • </soap:envelope>

  8. 服务调用 WSDL2JAVA XML2JAVA 服务描述CONTEXT Class Operation XML Message XML Message SOAP消息 SOAP消息 前置机 HTTP HTTP

  9. WSDL定义 • WSDL是XML描述的网络服务,基于消息机制、包含面向文本或面向过程信息的操作集合。 • 操作及消息的抽象定义与它们具体的网络实现和数据格式绑定是分离的,这样就可以重用这些抽象定义。 • 消息是需要交换数据的抽象描述; • 端点类型是操作的抽象集合。 • 针对一个特定端点类型的具体协议和数据格式规范构成一个可重用的绑定。 • 一个端点定义成网络地址和可重用的绑定的联接,端点的集合定义为服务。

  10. 服务接口定义和服务实现定义 • 服务接口组成了服务描述中的可重用部分, • type元素、message和portType。 • types元素中描述消息中复杂数据类型的使用。 • message元素指定XML 数据类型组成消息的各个部分。message 元素用于定义操作的输入和输出参数。 • portType元素中定义了Web服务的操作。操作定义了输入和输出数据流中可以出现的XML消息。

  11. 服务接口定义和服务实现定义 • 服务实现定义是一个描述给定服务提供者如何实现特定服务接口的WSDL文档。 • 有binding和services。 • binding 元素描述特定服务接口的协议、数据格式、安全性和其它属性。 • service元素。服务元素包含一组port元素。端口将端点与来自服务接口定义的binding 元素关联起来。

  12. WSDL是一种XML应用,它将Web Services描述定义为一组服务访问端点,客户端可以通过这些服务访问端点对包含面向文档信息或面向过程调用的服务进行访问。 • WSDL首先对访问的操作和访问时使用的请求/响应消息进行抽象描述,然后将其绑定到具体的传输协议和消息格式上,以最终定义具体部署的服务访问端点。 • 在具体使用中,可以使用任意的消息格式和网络协议。 • 在WSDL规范中,定义了如何使用SOAP消息格式、HTTP GET/POST消息格式以及MIME格式来完成Web Services交互的规范。

  13. WSDL特点 • 实现 Web 服务体系结构的松散耦合; • 无论是请求者还是提供者可以各自独立地使用平台、编程语言或分布式对象模型。

  14. 命名空间 • wsdl http://schemas.xmlsoap.org/wsdl/ • soap http://schemas.xmlsoap.org/wsdl/soap/ • http http://schemas.xmlsoap.org/wsdl/http/ • mime http://schemas.xmlsoap.org/wsdl/mime/ • soapenc http://schemas.xmlsoap.org/soap/encoding/ • soapenv http://schemas.xmlsoap.org/soap/envelope/ • xsi http://www.w3.org/2000/10/XMLSchema-instance • xsd http://www.w3.org/2000/10/XMLSchema

  15. WSDL文档框架 • <wsdl:definitions name="nmtoken"? targetNamespace="uri"?> • <import namespace="uri" location="uri"/>* • <wsdl:types> ? ……</wsdl:types> • <wsdl:message name=“nmtoken”>* • ……</wsdl:message> • <wsdl:portType name="nmtoken">* • ……</wsdl:portType> • <wsdl:binding name="nmtoken" type="qname">* • ……</wsdl:binding> • <wsdl:service name="nmtoken">*……</wsdl:service> • </wsdl:definitions>

  16. types元素 • <wsdl:types> ? • <wsdl:documentation .... />? • <xsd:schema .... />* • <-- extensibility element --> * • </wsdl:types>

  17. message元素 • <wsdl:message name="nmtoken"> * • <wsdl:documentation .... />? • <part name="nmtoken" • element="qname"? type="qname"?/> * • </wsdl:message>

  18. portType元素 • <wsdl:portType name="nmtoken">* • <wsdl:documentation .... />? • <wsdl:operation name="nmtoken">* • <wsdl:documentation .... /> ? • <wsdl:input name="nmtoken"? message="qname">? • <wsdl:documentation .... /> ? • </wsdl:input> • <wsdl:output name="nmtoken"? message="qname">? • <wsdl:documentation .... /> ? • </wsdl:output> • <wsdl:fault name="nmtoken" message="qname"> * • <wsdl:documentation .... /> ? • </wsdl:fault> • </wsdl:operation> • </wsdl:portType>

  19. binding元素 • <wsdl:binding name="nmtoken" type="qname">* • <wsdl:documentation .... />? • <-- extensibility element --> * • <wsdl:operation name="nmtoken">* • <wsdl:documentation .... /> ? • <-- extensibility element --> * • <wsdl:input> ? • <wsdl:documentation .... /> ? • <-- extensibility element --> • </wsdl:input> • <wsdl:output> ? • <wsdl:documentation .... /> ? • <-- extensibility element --> * • </wsdl:output> • <wsdl:fault name="nmtoken"> * • <wsdl:documentation .... /> ? • <-- extensibility element --> * • </wsdl:fault> • </wsdl:operation> • </wsdl:binding>

  20. service元素 • <wsdl:service name="nmtoken"> * • <wsdl:documentation .... />? • <wsdl:port name="nmtoken" binding="qname">* • <wsdl:documentation .... /> ? • <-- extensibility element --> • </wsdl:port> • <-- extensibility element --> • </wsdl:service>

  21. 类型 • types元素包含了交换消息的数据类型定义。为了实现最大的互操作性(interoperability)和平台中立性(neutrality),WSDL选用XML Schema DataTypes,简称XSD作为标准类型系统,并将它作为固有类型系统。 • <definitions .... > • <types> • <xsd:schema .... />* • </types> • </definitions>

  22. 类型—XSD编码抽象数据类型建议 • 使用元素(element)形式,而不使用属性(attribute)形式; • 不包括仅在特殊的协议和数据格式中使用的元素或者属性; • 数组类型使用Soap:Array 类型,并使用ArrayOfXXX作为数组类型的名; • 使用XSD编码表示xsd:anyType。

  23. <types> • <schema…> • <element name="PO" type="tns:POType"/> • <complexType name="POType"> • <element name="id" type="string/> • <element name="name" type="string"/> • <element name="items"> • <complexType> • <element name="item" type="tns:Item" minOccurs="0“ • maxOccurs="unbounded"/> • </complexType> • </element> • </complexType> • <complexType name="Item"> • <element name="quantity" type="int"/> • <element name="product" type="string"/> • </complexType> • <element name="Customer" type="tns:CustomerType"/> • <complexType name="CustomerType"> • <element name="name" type="string"/> • </complexType> • </schema> • </types>

  24. 消息 • 消息由若干个逻辑部件(part)构成。每个部件使用一个消息类型属性与某个类型系统的类型相关联。 • 消息定义与法如下: • <definitions .... > • <message name="nmtoken"> * • <part name="nmtoken" • element="qname"? type="qname"?/> * • </message> • </definitions> • 消息(message)name属性指定了消息的名称。 • 如果消息具有多个逻辑单位,则需要使用多个part元素。

  25. 消息示例 • <message name="PO"> • <part name="po" element="tns:PO"/> • <part name="customer" element="tns:Customer"/> • </message> • <message name="P1"> • <part name=“address" type=“XSD:string"/> • </message> • <message name="P2"> • <part name="composite" type="tns:Composite"/> • </message>

  26. s=λ(&s,"definition\*") • 在WSDL文档中,消息名称定义具有唯一性,即 • xλ(&s,"message") • (yλ(&s,"message","name",σ(&x,"name"))x=y) • 在消息定义中,部件名称定义具有唯一性,即 • xλ(&s,"message") • yλ(&x,"message\part") • (zλ(&x,"message\part","name",σ(&y,"name")) • y=z)

  27. 消息类型属性集合是可扩展的。WSDL定义如下消息类型属性消息类型属性集合是可扩展的。WSDL定义如下消息类型属性 • element:使用QName引用一个XSD元素,即 • xλ(&s, "message\part") • (σ(&x,"element") • !yλ(&s,"types\schema\element") • σ(&x,"element")=σ(&y,"name"))) • type:使用QName引用个XSD simpleType(简单类型)或XSD complexType (复含类型),即 • xλ(&s,"message\part") • (σ(&x,"type") • σ(&x,"type")XSDtypes) • yλ(&s,"types\schema\complexType") • (σ(&x,"type")=σ(&y,"name")) • yλ(&s,"types\schema\simpleType") • (σ(&x,"type")=σ(&y,"name")))

  28. 端口类型定义 • 端口类型是一个由抽象操作和抽象消息构成的有名称的集合。 • <wsdl:definitions .... > • <wsdl:portType name="nmtoken"> * • <wsdl:operation name="nmtoken"> • <wsdl:input name="nmtoken"? message="qname"/> • <wsdl:output name="nmtoken"? message="qname"/> • <wsdl:fault name="nmtoken" message="qname"/>* • </wsdl:operation> • </wsdl:portType > • </wsdl:definitions> • 端口类型定义的name属性表示端口类型名称,操作定义的name属性表示操作名称。

  29. s=λ(&s,"definition\*") • 端口类型名称具有唯一性,即 • xλ(&s,"portType") • (yλ(&s,"portType","name",σ(&x,"name")) • x=y) • 在相同端口类型中,操作名称具有唯一性,即 • xλ(&s,"portType") • yλ(&x,"portType\operation") • (zλ(&x,"portType\operation","name",σ(&y,"name")) • y=z)

  30. 在不同的端口类型中,如果操作名称相同,则操作定义相同。在不同的端口类型中,如果操作名称相同,则操作定义相同。 • xλ(&s,"portType\operation") • (yλ(&s,"portType\operation","name",σ(&x,"name")) x=y) • 操作的input、output和fault元素的message属性所指定的消息,在WSDL的message中已定义,即 • xλ(&s,"portType\operation\input") • yλ(&s,"message")(σ(&x,"message")=σ(&y,"name")) • xλ(&s,"portType\ operation\output") •  yλ(&s,"message")(σ(&x,"message")=σ(&y,"name")) • xλ(&s,"portType\ operation\fault") •  yλ(&s,"message")(σ(&x,"message")=σ(&y, "name"))

  31. 操作 • WSDL支持4种消息交换方式,来访问服务端点。 • 单向(One-way):服务访问端点接收消息; • 请求响应(Request-response):服务访问端点接收请求消息,然后发送响应消息; • 要求应答(Solicit-response):服务访问端点发送要求消息,然后接收应答消息; • 通知(Notification):服务访问端点发送通知消息。 • 操作中引用到的消息通过message属性指定。

  32. 单向操作 • 单向操作语法: • <wsdl:definitions .... > • <wsdl:portType .... > * • <wsdl:operation name="nmtoken"> • <wsdl:input name="nmtoken"? message="qname"/> • </wsdl:operation> • </wsdl:portType > • </wsdl:definitions> • input元素指定用于单向操作的抽象消息格式。

  33. 请求响应操作 • 请求响应操作语法 • <wsdl:definitions .... > • <wsdl:portType .... > * • <wsdl:operation name="nmtoken" • parameterOrder="nmtokens"> • <wsdl:input name="nmtoken"? message="qname"/> • <wsdl:output name="nmtoken"? message="qname"/> • <wsdl:fault name="nmtoken" message="qname"/>* • </wsdl:operation> • </wsdl:portType > • </wsdl:definitions>

  34. 要求应答操作 • 要求应答操作语法 • <wsdl:definitions .... > • <wsdl:portType .... > * • <wsdl:operation name="nmtoken" • parameterOrder="nmtokens"> • <wsdl:output name="nmtoken"? message="qname"/> • <wsdl:input name="nmtoken"? message="qname"/> • <wsdl:fault name="nmtoken" message="qname"/>* • </wsdl:operation> • </wsdl:portType > • </wsdl:definitions>

  35. 通知操作 • 通知操作语法 • <wsdl:definitions .... > • <wsdl:portType .... > * • <wsdl:operation name="nmtoken"> • <wsdl:output name="nmtoken"? • message="qname"/> • </wsdl:operation> • </wsdl:portType > • </wsdl:definitions>

  36. 操作中的元素名称 • 如果单向操作和通知操作未指定name属性,则该属性名默认为是操作名。 • 如果请求响应或要求应答操作中未指定name属性,则该属性名默认为是 • 操作名+“Request”/“Responese”/“Solicit”。 • 针对于请求应答和要求应答操作可以通过parameterOrder指定一个参数名列表。该属性的值是一个用空格分开的消息构件名序列 。

  37. 绑定 • 绑定语法如下: • <wsdl:definitions .... > • <wsdl:binding name="nmtoken" type="qname"> * • <-- extensibility element (1) --> * • <wsdl:operation name="nmtoken"> * • <-- extensibility element (2) --> * • <wsdl:input name="nmtoken"? > ? • <-- extensibility element (3) --> • </wsdl:input> • <wsdl:output name="nmtoken"? > ? • <-- extensibility element (4) --> * • </wsdl:output> • <wsdl:fault name="nmtoken"> * • <-- extensibility element (5) --> * • </wsdl:fault> • </wsdl:operation> • </wsdl:binding> • </wsdl:definitions>

  38. 服务与访问端点 • 访问端点(port)通过为绑定指定唯一地址来定义一个访问端点。访问端点语法如下: • <wsdl:definitions .... > • <wsdl:service .... > * • <wsdl:port name="nmtoken" binding="qname">* • <-- extensibility element (1) --> • </wsdl:port> • </wsdl:service> • </wsdl:definitions> • 在WSDL文档范围内,访问端点的name属性具有唯一性。

  39. 服务 • 服务是访问端点集合,服务语法如下: • <wsdl:definitions .... > • <wsdl:service name="nmtoken">* • <wsdl:port ..../>* • </wsdl:service> • </wsdl:definitions> • 在WSDL文档中,服务的name属性具有唯一性。

  40. 服务中的访问端点具有如下的关系: • 所有访问端点都不相互通信,即一个服务的访问端点的输出不会是另一个访问端点的输入。 • 如果一个服务中有多个访问端点属于同一端口类型,但是对应不同的绑定或者地址,则这些访问端点可以相互替换。这使得WSDL文档使用者根据需要选择访问端点。 • 通过检查访问端点可以确定服务的端口类型。这使得WSDL文档的使用者能够根据它支持的端口类型决定是否与一个特定的服务通讯。

  41. SOAP绑定 • <binding…> • <soap:binding style="rpc|document" transport="uri"> • <operation…> • <soap:operation soapAction="uri"? style="rpc|document"?>? • <input> • <soap:body parts="nmtokens"? use="literal|encoded" • encodingStyle="uri-list"? namespace="uri"?> • <soap:header element="qname" fault="qname"?>* • </input> • <output> • <soap:body parts="nmtokens"? use="literal|encoded" • encodingStyle="uri-list"? namespace="uri"?> • <soap:header element="qname" fault="qname"?>* • </output> • <fault>* • <soap:fault name="nmtoken" use="literal|encoded" • encodingStyle="uri-list"? namespace="uri"?> • </fault> • </operation> • </binding>

  42. soap:binding元素 • SOAP:binding元素表明WSDL文档绑定到SOAP协议格式,该元素在使用SOAP绑定时是必需的。 • <definitions .... > • <binding .... > • <soap:binding transport="uri"? • style="rpc|document"?> • </binding> • </definitions> • style属性值是它所包含的操作子元素的style属性的默认值。 • transport属性是必需的,它的值表示绑定的传输方式与SOAP的何种传输方式一致。URI值http://schemas.xmlsoap.org/soap/http 表示传输方式和SOAP规范的HTTP绑定相一致。

  43. soap:operation • <definitions .... > • <binding .... > • <operation .... > • <soap:operation soapAction="uri"? • style="rpc|document"?>? • </operation> • </binding> • </definitions>

  44. soap:body • <definitions .... > • <binding .... > • <operation .... > • <input> • <soap:body parts="nmtokens"? use="literal|encoded"? • encodingStyle="uri-list"? • namespace="uri"?> • </input> • <output> • <soap:body parts="nmtokens"? use="literal|encoded"? • encodingStyle="uri-list"? namespace="uri"?> • </output> • </operation> • </binding> • </definitions>

  45. soap:fault • <definitions .... > • <binding .... > • <operation .... > • <fault>* • <soap:fault name="nmtoken" • use="literal|encoded" • encodingStyle="uri-list"? • namespace="uri"?> • </fault> • </operation> • </binding> • </definitions>

  46. soap:header和soap:headerfault • <definitions .... > • <binding .... > • <operation .... > • <input> • <soap:header message="qname" part="nmtoken" use="literal|encoded" • encodingStyle="uri-list"? namespace="uri"?>* • <soap:headerfault message="qname" part="nmtoken" use="literal|encoded" • encodingStyle="uri-list"? namespace="uri"?/>* • <soap:header> • </input> • <output> • <soap:header message="qname" part="nmtoken" use="literal|encoded" • encodingStyle="uri-list"? namespace="uri"?>* • <soap:headerfault message="qname" part="nmtoken" use="literal|encoded" • encodingStyle="uri-list"? namespace="uri"?/>* • <soap:header> • </output> • </operation> • </binding> • </definitions>

  47. soap:address • <definitions .... > • <port .... > • <soap:address location="uri"/> • </port> • </definitions>

  48. binding binding binding port port port port portType、binding与port • 一个portType可以对应多个bindng • 一个binding可以对应多个port portType

  49. 消息传递模式 • 1.rpc/encoded • 2.rpc/literal • 3.document/encoded • 4.document/literal

  50. 服务 • public class myServices { • public void myMethod (int x){ • return • } • }

More Related