分享

如何看懂一个WSDL文档

 chanvy 2008-11-13
如何看懂一个WSDL文档
 

WSDL 指网络服务描述语言 (Web Services Description Language)。一个WSDL文档是一个服务的描述,它描述了:服务名,服务地址,服务能用什么协议访问,服务有哪些方法,每个方法有几部分参数,每个参数的类型。

在一个WSDL文档中,你最经常看到的元素前缀会有wsdlsoapxsd。当然这些前缀是与命名空间URI对应的,前缀是可以自己定义的,或许与此不同,但大都这么定义。

WSDL在设计时,充分考虑了,各个元素模块的重用(好像一个类中定义了一些方法,可被不同方法共同调用)如:wsdl:binding、wsdl:portType、wsdl:message,你定义的这个元素可能被几个地方引用到。所以WSDL设计者把它设计的够精简、灵活。

下面我基于WSDL 1.2 语法分别对三个命名空间的经常用到的元素解释一下:最好从下往上看

//文档的根元素,表示这是一个服务的定义,在此定义中默认的名字空间URIhttp://mple”.
<wsdl:definitions xmlns:axis2="http://mple" xmlns:mime="http://schemas./wsdl/mime/" xmlns:ns0="http://mple/xsd" xmlns:soap12="http://schemas./wsdl/soap12/" xmlns:http="http://schemas./wsdl/http/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:xs="http://www./2001/XMLSchema" xmlns:soap="http://schemas./wsdl/soap/" xmlns:wsdl="http://schemas./wsdl/" targetNamespace="http://mple">
<wsdl:documentation>
        This service is to get the running Axis version
    </wsdl:documentation>

//为它表示所有消息中能使用的基本元素类型,如一个方法三个参数的其中一个参数的类型。
<wsdl:types>
   <xs:schema xmlns:ns="http://mple/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://mple/xsd">

//为了最大程度的平台中立性,WSDL 使用 XML Schema 语法来定义数据类型

    <xs:element name="ExceptionFault">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="Exception" nillable="true" type="xs:anyType"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
    <xs:element name="getVersionResponse">
     <xs:complexType>
      <xs:sequence>
       <xs:element name="return" nillable="true" type="xs:string"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
   </xs:schema>
</wsdl:types>

//这是定义一个消息,是一次服务调用的一个消息。也就是下面的方法可以用到(指定)的方法参数。

<wsdl:message name="getVersionMessage"/>
<wsdl:message name="getVersionResponse">
   <wsdl:part name="part1" element="ns0:getVersionResponse"/>//
这是这个消息的第一人部分,同方法的第一个参数
</wsdl:message>
<wsdl:message name="getVersionFault">
   <wsdl:part name="part1" element="ns0:ExceptionFault"/>
</wsdl:message>

*//端口类型,它表示被某种端口类型(访问协议)指定的一组可被这个端口执行的操作,以及相关消息,你可以它理解为可被调用的一个函数库。  
<wsdl:portType name="VersionPortType">

//操作,它表示其中一个操作
   <wsdl:operation name="getVersion">

//输入,用它指定一个输入消息
    <wsdl:input xmlns:wsaw="http://www./2006/05/addressing/wsdl" message="axis2:getVersionMessage" wsaw:Action="urn:getVersion"/>

//输出,用它指定一个返回消息
    <wsdl:output message="axis2:getVersionResponse"/>

//错误,用它指明发生错误时,返回的消息
    <wsdl:fault message="axis2:getVersionFault" name="getVersionFault"/>
   </wsdl:operation>
</wsdl:portType>

//绑定,此元素详细描述了某个端口,的消息传输协议和消息包装格式。(用于服务器端收到消息中的解析)
<wsdl:binding name="VersionSOAP11Binding" type="axis2:VersionPortType">
   <soap:binding transport="http://schemas./soap/http" style="document"/>

//此处用于表示,当收到一个消息请求方法为“urn:getVersion”时,用此元素包含的描述定义来解析此消息。并确定消息所请求的方法所对应的服务的方法“wsdl:operation name="getVersion”。   <wsdl:operation name="getVersion">
    <soap:operation soapAction="urn:getVersion" style="document"/>
    <wsdl:input>
     <soap:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
     <soap:body use="literal"/>
    </wsdl:output>
    <wsdl:fault name="getVersionFault">
     <soap12:fault use="literal" name="getVersionFault"/>
    </wsdl:fault>
   </wsdl:operation>
</wsdl:binding>

//SOAP:binding是采用SOAP1.1版本。soap12:binding是采用SOAP1.2版本, 并且是采用SOAP规范来形成HTTPRequest
<wsdl:binding name="VersionSOAP12Binding" type="axis2:VersionPortType">
   <soap12:binding transport="http://schemas./soap/http" style="document"/>
   <wsdl:operation name="getVersion">
    <soap12:operation soapAction="urn:getVersion" style="document"/>
    <wsdl:input>
     <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
     <soap12:body use="literal"/>
    </wsdl:output>
    <wsdl:fault name="getVersionFault">
     <soap12:fault use="literal" name="getVersionFault"/>
    </wsdl:fault>
   </wsdl:operation>
</wsdl:binding>

//此binding 是采用HTTP规范来填写消息内容
<wsdl:binding name="VersionHttpBinding" type="axis2:VersionPortType">
   <http:binding verb="POST"/>
   <wsdl:operation name="getVersion">
    <http:operation location="getVersion"/>
    <wsdl:input>
     <mime:content type="text/xml"/>
    </wsdl:input>
    <wsdl:output>
     <mime:content type="text/xml"/>
    </wsdl:output>
   </wsdl:operation>
</wsdl:binding>

//此元素用于描述一个服务定义中其中的一个服务(可定义多个服务)。和此服务所有可访问的端口和访问地址
<wsdl:service name="Version">
   <wsdl:port name="VersionSOAP11port_http" binding="axis2:VersionSOAP11Binding">
    <soap:address location="http://192.9.107.58:8080/axis2/services/Version"/>
   </wsdl:port>
   <wsdl:port name="VersionSOAP12port_http" binding="axis2:VersionSOAP12Binding">
    <soap12:address location="http://192.9.107.58:8080/axis2/services/Version"/>
   </wsdl:port>

   <wsdl:port name="VersionHttpport" binding="axis2:VersionHttpBinding">
    <http:address location="http://192.9.107.58:8080/axis2/services/Version"/>
   </wsdl:port>
</wsdl:service>
</wsdl:definitions>

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多