WSDL简介及WSDL如何查看

**WSDL 指网络服务描述语言 (Web Services Description Language)。一个WSDL文档是一个服务的描述,它描述了:服务名,服务地址,服务能用什么协议访问,服务有哪些方法,每个方法有几部分参数,每个参数的类型。
在一个WSDL文档中,你最经常看到的元素前缀会有wsdl、soap、xsd。当然这些前缀是与命名空间URI对应的,前缀是可以自己定义的,或许与此不同,但大都这么定义。
WSDL在设计时,充分考虑了,各个元素模块的重用(好像一个类中定义了一些方法,可被不同方法共同调用)如:wsdl:binding、wsdl:portType、wsdl:message,你定义的这个元素可能被几个地方引用到。所以WSDL设计者把它设计的够精简、灵活。*强调内容*
下面我基于WSDL 1.2 语法分别对三个命名空间的经常用到的元素解释一下:最好从下往上看
//文档的根元素,表示这是一个服务的定义,在此定义中默认的名字空间URI为“http://axisversion.sample”.

<wsdl:definitions xmlns:axis2="http://axisversion.sample" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns0="http://axisversion.sample/xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://axisversion.sample">
<wsdl:documentation>
        This service is to get the running Axis version
    </wsdl:documentation>

//为它表示所有消息中能使用的基本元素类型,如一个方法三个参数的其中一个参数的类
了最大程度的平台中立性,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: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.w3.org/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.xmlsoap.org/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.xmlsoap.org/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>
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值