是不是经常有人在开发的时候,特别是和第三方有接口的时候,走的是SOAP协议,然后用户给你一个WSDL文件,说按照上面的进行适配,嘿嘿,这个时候,要是你以前没有开发过,肯定会傻眼,那如果你想学习的话,就认真的看下面的讲解咯:
一、WSDL概述
二、WSDL基本结构
三、WSDL声明
definition元素的的一个属性是name,此属性不重要可以没有;
<!--
< message
</ message >
< message
</ message >
<!--
< portType
</ portType >
< definitions
< types >
</ types >
</ definitions
四、WSDL抽象接口
RPC式样的Web服务的message服务
GetBulkBookPriceRequest表示消息的输入(相当于函数的参数),GetBulkBookPriceResponse
Web
RPC样式用类型来数据定义过程调用,调用中的每一个元素表示某一个类型的参数。
< types >
文档式样Web服务的Messages元素:
当用户采用文档式样消息传递模式的时候,messages元素要应用types定义中的顶级元素。具体顶级元素的定义和XML
消息部分使用element属性定义
文档式样的消息传递要交换XML文档,并且应用它们的顶级元素。
注:Messages元素的RPC/Document试样对应了SOAP
< types >
声明错误消息:
错误使用的消息定义只能采用Document/Literal编码样式
上面声明了匿名类型,InvalidIsbnFaultDetail不需要type类型,complexType中也不包括name属性,详细见Web
</ message >
< message
</ message >
< message
< portType
< fault
</ portType >
Input表示传递到Web服务的有效负载;output表示返回给客户的有效负载;可以不包括,也可以包括一个或者多个fault错误消息。
parameterOrder定义了input和output消息采用的正确的顺序
使用parameterOrder的时候,必须包含所有输入参数部分;并且只包含不是返回类型的输出部分,如果output只有一个part(上例),会假设返回值,所以不包括在parameterOrder中
如果parameterOrder列出output中的part部分,那么这个将被作为OUT参数,如果input元素和output元素使用相同的名称声明了一个部分的时候,此部分为INOUT参数
五、WSDL实现:binding元素
soapbind:binding元素指定了用于传输SOAP消息的Internet协议以及operation缺省的消息类型(RPC还是文档类型)
http://schemas.xmlsoap.org/soap/http表示采用的是HTTP的传输方式,当然也可以用HTTPS,用户具体使用HTTP还是HTTPS取决于Port元素中定义的location属性声明中的模式。
上面的rpc表示缺省状态下:operation将采用RPC的方式传递消息负载。
POST
Host:
Content-Type:
Content-Length:
SOAPAction="http://www.Monson-Haefel.com/jwsbook/BookQuote/GetBookPrice"
soapbind:operation元素指定了消息传递样式(RPC或者document),并且指定了SOAPAction字段的值。
上面的例子显示在HTTP消息中的SOAPAction中对应的值
< soapbind:operation
< input >
< operation
</ operation >
soapbind:body元素有四个属性use、namespace、part和encodingStyle
对于WS-I
在RPC样式中,必须用一个有效的URI指定的namespace属性。此URI可以于WSDL文档的targetNampspce相同;而在document样式中不能使用namespace,XML文档样式的命名空间派生于它的XML文档
</ fault >
< portType
</ portType >
soapbind:fault元素和fault元素包含一个强制性的name属性,表示要引用声明于对应portType中的专有错误消息
< xsd:schema
targetNamespace ="http://www.Monson-Haefel.com/jwsbook/BookQuote"
</ types >
<!--
< operation
WSDL在绑定的input元素、output元素中利用soapbind:header元素显式指定了一个SOAP头文件
< input >
soapbind:headerfault元素表述了Header专用的错误消息,如果有一个响应消息,必须在消息的Header元素中返回各种header的专用错误。
SOAP没有就如何提供Header错误方面给出详细说明,只是要求必须在Header元素中包含detail元素。有些SOAP工具箱将SOAP的fault放在header元素中。
六、WSDL实现:Service和Port元素
</ service >
Service元素包含一个或者多个Port元素
每一个Port元素对应一个不同的Web服务,port将一个URL赋予一个特定的binding,通过location实现
可以使两个或者多个port元素将不同的URL赋给相同的binding,例如负载平衡和容错的时候,使用这种方法。
soapbind:address:将Internet地址通过location属性赋予一个SOAP绑定。