wxdl文件详解

一个WSDL文档的根元素是definitions元素,WSDL文档包含7个重要的元素:types,import, message, portType, operations, binding和service元素。

WSDL声明部分

WSDL的声明部分包含:XML声明、Definition定义

1、XML声明

[html] view plain copy

1.  version="1.0" encoding="UTF-8"?>  

  WSDL的声明必须定义成使用:UTF-8 或者UTF-16 编码。

2、definition元素

所有WSDL文档的根元素都是definition元素。   

[html] view plain copy

1.  name="BookQuoteWS"  

2.                       targetNamespace="http://www.Monson-Haefel.com/jwsbook/BookQuote"  

3.                       xmlns:mh="http://www.Monson-Haefel.com/jwsbook/BookQuote"  

4.                       xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/"  

5.                          xmlns:xsd="http://www.w3.org/2001/XMLSchema"  

6.                      xmlns="http://schemas.xmlsoap.org/wsdl/">  

7.   

8.   

9.   

10. name="GetBookPriceRequest">  

11.  

12.       name="isbn" type="xsd:string" />  

13.  

14.  

15.  

16. name="GetBookPriceResponse">  

17.  

18.      name="price" type="xsd:float" />  

19.  

20.  

21.  

22.  

23.  

24. name="BookQuote">  

25.  

26.     name="getBookPrice">  

27.  

28.           name="isbn" message="mh:GetBookPriceRequest"/>  

29.  

30.           name="price" message="mh:GetBookPriceResponse"/>  

31.  

32.    

33.  

34.  

(1) definition元素中一般包括若干个XML命名空间;
 http://schemas.xmlsoap.org/wsdl/
是默认的命名空间,这样就可以不用显式地定义每一个WSDL元素的命名空间了,例如: …;文档中所有的元素缺省应该属于这个命名空间。
(2)definition元素的的一个属性是name,此属性不重要可以没有;
(3)定义了targetNamespace命名空间,它为在模式中显式创建的所有新类型均声明了XML命名空间,而且上面的例子中赋予了mh前缀。

(4)上面的例子中:message元素利用name属性指定了标签(例如:GetBookPriceRequest),这些标签会自动使用targetNamespace的命名空间,标签了的messages元素通常被称为定义。

(5)文档中的其他元素用标签和命名空间前缀去应用定义,例如上面的例子中:input元素是使用mh:GetBookPriceRequest来引用标签GetBookPriceRequest。

3、Types元素
Types元素用作一个容器,定义了自定义的特殊数据类型,在声明消息部分(有效负载)的时候,messages定义使用了types元素中定义的数据类型与元素。

[html] view plain copy

1.  version="1.0" encoding="UTF-8"?>  

2.   

3.  name="BookQuoteWS"  

4.                       targetNamespace="http://www.Monson-Haefel.com/jwsbook/BookQuote"  

5.                       xmlns:mh="http://www.Monson-Haefel.com/jwsbook/BookQuote"  

6.                       xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/"  

7.                       xmlns:xsd="http://www.w3.org/2001/XMLSchema"  

8.                      xmlns="http://schemas.xmlsoap.org/wsdl/">  

9.   

10.  

11.       targetNamespace="http://www.Monson-Haefel.com/jwsbook/BookQuote">  

12.  

13.        

14.  

15.       name="ISBN">  

16.  

17.         base="xsd:string">  

18.  

19.           value="[0-9]{9}[0-9Xx]" />  

20.  

21.          

22.  

23.        

24.  

25.      

26.  

27.  


types
元素作为一个容器,用来定义XML模式内置的数据类型(即复杂类型和定制的简单类现,详细见Web Service XML文章)中没有描述的各种数据类型。例如:ISBN。
上面的例子中,types元素中直接嵌套了一个完整的W3C XML模式文档,此文档中targetNamespace必须是一个有效的非空值,而且必须属于由WSDL文档。

4、Import元素
            Import元素可以让当前的文档使用其他WSDL文档中指定命名空间中的定义。 

[html] view plain copy

1.  name="AllMhWebServices"  

2.          xmlns="http://schemas.xmlsoap.org/wsdl/">  

3.   

4.      namespace="http://www.Monson-Haefel.com/jwsbook/BookQuote"  

5.   

6.      location="http://www.Monson-Haefel.com/jwsbook/BookPrice.wsdl"/>  

7.   

8.      namespace="http://www.Monson-Haefel.com/jwsbook/po"  

9.   

10.     location="http://www.Monson-Haefel.com/jwsbook/wsdl/PurchaseOrder.wsdl"/>  

11.  

12.     namespace="http://www.Monson-Haefel.com/jwsbook/Shipping"  

13.  

14.     location="http://www.Monson-Haefel.com/jwsbook/wsdl/Shipping.wsdl"/>  

15.  

16. >  

WSDL的import元素必须声明两个属性,即namespace属性和location属性。
 namespace
属性必须和正导入的WSDL文档中声明的targetNamespace相匹配。
location
属性必须指向一个实际的WSDL文档。

WSDL抽象接口

 Message、portType和operation元素用于描述Web服务的抽象接口,相当于JAVA或者C++中编程中的类的接口。其中portType相当于类接口的名称;operation相当于接口中包含的函数,message相当于函数的参数和返回值。

1、Message元素
 Message元素描述了Web服务的有效负载。相当于函数调用中的参数和返回值。

[html] view plain copy

1.  name="GetBulkBookPriceRequest">  

2.   

3.      name="isbn" type="xsd:string"/>  

4.   

5.      name="quantity" type="xsd:int"/>  

6.   

7.     

8.   

9.    name="GetBulkBookPriceResponse">  

10.  

11.     name="price" type="mh:prices" />  

12.  

13.    

GetBulkBookPriceRequest表示消息的输入(相当于函数的参数),GetBulkBookPriceResponse表示消息的输出(相当于函数的返回值)。
Web Service
的输入和输出参数可以是多个(一个特点),每一个输入或者输出使用part元素定义。

2、portType元素
 PortType元素定义了Web服务的抽象接口,它可以由一个或者多个operation元素,每个operation元素定义了一个RPC样式或者文档样式的Web服务方法。

3、operation元素
Operation元素要用一个或者多个messages消息来定义它的输入、输出以及错误。

[html] view plain copy

1.  name="GetBulkBookPriceRequest">  

2.   

3.    name="isbn" type="xsd:string"/>  

4.   

5.    name="quantity" type="xsd:int"/>  

6.   

7.   

8.   

9.  name="GetBulkBookPriceResponse">  

10.  

11.   name="prices" type="mh:prices" />  

12.  

13.  

14.  

15. name="InvalidArgumentFault">  

16.  

17.     name="error_message" element="mh:InvalidIsbnFaultDetail" />  

18.  

19.    

20.  

21. name="GetBulkBookPrice" >  

22.  

23.   name="getBulkBookPrice" parameterOrder="isbn quantity">  

24.  

25.      name="request" message="mh:GetBulkBookPriceRequest"/>  

26.  

27.      name="prices" message="mh:GetBulkBookPriceResponse"/>  

28.  

29. name="InvalidArgumentFault" message="mh:InvalidArgumentFault"/>  

30.  

31.    

32.  

33.  


Input表示传递到Web服务的有效负载;output表示返回给客户的有效负载;可以不包括,也可以包括一个或者多个fault错误消息。

parameterOrder定义了input和output消息采用的正确的顺序

使用parameterOrder的时候,必须包含所有输入参数部分;并且只包含不是返回类型的输出部分,如果output只有一个part(上例),会假设返回值,所以不包括在parameterOrder中


如果parameterOrder列出output中的part部分,那么这个将被作为OUT参数,如果input元素和output元素使用相同的名称声明了一个部分的时候,此部分为INOUT参数.

WSDL实现部分

1、binding元素

Binding元素将一个抽象的portType映射到一组具体的协议(SOAP或者HTTP)、消息传递样式(RPC或者document)以及编码样式(literal或者SOAP encoding)。

binding 元素有两个属性 - name 属性和type 属性。name 属性定义 binding 的名称,而 type 属性指向用于 binding 的端口

1.1 soap:binding元素

[html] view plain copy

1.  name="BookPrice_Binding" type="mh:BookQuote">  

2.   

3.    style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>  

4.   

5.    name="getBookPrice">  

soap:binding元素指定了用于传输SOAP消息的Internet协议以及operation缺省的消息类型(RPC还是文档类型)

http://schemas.xmlsoap.org/soap/http表示采用的是HTTP的传输方式,当然也可以用HTTPS,用户具体使用HTTP还是HTTPS取决于Port元素中定义的location属性声明中的模式。

上面的rpc表示缺省状态下:operation将采用RPC的方式传递消息负载。

1.2 soap:operation元素

[html] view plain copy

1.  name="getBookPrice">  

2.   

3.      style="rpc" soapAction="http://www.Monson-Haefel.com/jwsbook/BookQuote/GetBookPrice"/>  

4.   

5. POST 1ed/BookQuote HTTP/1.1  

6.   

7. Host: www.Monson-Haefel.com  

8.   

9. Content-Type: text/xml; charset="utf-8"  

10.  

11.Content-Length: nnnn  

12.  

13.SOAPAction="http://www.Monson-Haefel.com/jwsbook/BookQuote/GetBookPrice"  

soap:operation元素指定了消息传递样式(RPC或者document),并且指定了SOAPAction字段的值。上面的例子显示在HTTP消息中的SOAPAction中对应的值
1.3soap:body
元素

[html] view plain copy

1.  name="getBookPrice">  

2.   

3.  style="rpc"/>  

4.   

5.         

6.   

7.            use="literal"  

8.   

9.           namespace="http://www.Monson-Haefel.com/jwsbook/BookQuote" />  

10.  

11.         

12.  

13.         

14.  

15.           use="literal"  

16.  

17.          namespace="http://www.Monson-Haefel.com/jwsbook/BookQuote" />  

18.  

19.         

20.  

21. name="submit">  

22.  

23.   style="document"/>  

24.  

25.        

26.  

27.         use="literal" />  

28.  

29.        

30.  

31.        

32.  

33.         use="literal" />  

34.  

35.        

36.  

37.  

soapbind:body元素有四个属性use、namespace、part和encodingStyle

对于WS-I use的属性值必须是literal,意味这不是用编码的方式,所以永远不会用到encodingStyle属性

在RPC样式中,必须用一个有效的URI指定的namespace属性。此URI可以于WSDL文档的targetNampspce相同;而在document样式中不能使用namespace,XML文档样式的命名空间派生于它的XML文档。

1.4 soap:fault元素

[html] view plain copy

1.  name="InvalidArgumentFault">  

2.   

3.       name="InvalidArgumentFault" use="literal" />  

4.   

5.   

6.   

7.  name="BookQuote">  

8.   

9.    name="getBookPrice">  

10.  

11.      name="isbn" message="mh:GetBookPriceRequest"/>  

12.  

13.      name="price" message="mh:GetBookPriceResponse"/>  

14.  

15.      name="InvalidArgumentFault" message="mh:InvalidArgumentFault"/>  

16.  

17.    

18.  

19.  

soap:fault元素和fault元素包含一个强制性的name属性,表示要引用声明于对应portType中的专有错误消息。

1.5 soap:header元素

[html] view plain copy

1.   

2.   

3.    

4.   

5. targetNamespace="http://www.Monson-Haefel.com/jwsbook/BookQuote"  

6.   

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

8.   

9.          name="message-id" type="string" />  

10.  

11.      

12.  

13.  

14.  

15.   

16.  

17.  

18.  

19.   name="Headers">  

20.  

21.     name="message-id" element="mh:message-id" />  

22.  

23.    

24.  

25.   

26.  

27. name="getBookPrice">  

28.  

29.    

30.  

31.      message="mh:Headers" part="message-id" use="literal" />  

32.  

33.      use="literal"  

34.  

35.           namespace="http://www.Monson-Haefel.com/jwsbook/BookQuote" />  

36.  

37.    

WSDL在绑定的input元素、output元素中利用soapbind:header元素显式指定了一个SOAP头文件

1.6 soap:headerfault
元素  

[html] view plain copy

1.   

2.   

3.    name="HeaderFault">  

4.   

5.      name="faultDetail" element="mh:detailMessage" />  

6.   

7.     

8.   

9.   

10.  

11.       message="mh:Header" use="literal">  

12.  

13.          message="mh:Headers" use="literal" />  

14.  

15.        

16.  

17.       use="literal"  

18.  

19.           namespace="http://www.Monson-Haefel.com/jwsbook/BookQuote" />  

20.  

21.  


soap:headerfault元素表述了Header专用的错误消息,如果有一个响应消息,必须在消息的Header元素中返回各种header的专用错误。

SOAP没有就如何提供Header错误方面给出详细说明,只是要求必须在Header元素中包含detail元素。有些SOAP工具箱将SOAP的fault放在header元素中。

2、Service和Port元素

[html] view plain copy

1.  name="BookPriceService">  

2.   

3.    name="BookPrice_Port" binding="mh:BookPrice_Binding">  

4.   

5.      location=  

6.   

7.      "http://www.Monson-Haefel.com/jwsbook/BookQuote" />  

8.   

9.     

10.  

11.   name="BookPrice_Failover_Port" binding="mh:BookPrice_Binding">  

12.  

13.     location=  

14.  

15.     "http://www.monson-haefel.org/jwsbook/BookPrice" />  

16.  

17.    

18.  

19.   name="SubmitPurchaseOrder_Port"  

20.  

21.   binding="mh:SubmitPurchaseOrder_Binding">  

22.  

23.     location=  

24.  

25.     "https://www.monson-haefel.org/jwsbook/po" />  

26.  

27.    

28.  

29.  

Service元素包含一个或者多个Port元素

每一个Port元素对应一个不同的Web服务,port将一个URL赋予一个特定的binding,通过location实现

可以使两个或者多个port元素将不同的URL赋给相同的binding,例如负载平衡和容错的时候,使用这种方法。

soapbind:address:将Internet地址通过location属性赋予一个SOAP绑定。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部