WSDL文件详解

WSDL文件详解

一、WSDL简介

W3school 上的定义:WSDL 指 WSDL 指网络服务描述语言 (Web Services Description Language)。WSDL 是一种使用 XML 编写的文档。这种文档可描述某个 Web service。它可规定服务的位置,以及此服务提供的操作(或方法)。其中我们可以得知几点:

1、WSDL是XML文档。

2、WSDL描述了某个web service 。如何描述的呢?规定了服务的位置和该服务内有哪些方法。

这其实也可以认为是描述了某个接口,并指出了接口的位置,看到这个文档可以调用某个接口了。

二、WSDL文档结构

(一)端口

元素是最重要的 WSDL 元素。它可描述一个 web service、可被执行的操作,以及相关的消息。可以看作一个模块。

如下:

<wsdl:portType name="PAPNManagementPortType">
    <!-- operation 相当于该类里有一个方法名,方法名为processAPNManagement -->
    <wsdl:operation name="processAPNManagement"> 
        <!--input 方法里有一个输入消息 -->
        <wsdl:input name="APNMRequest" message="tns:APNMRequest"/>
        <!--output 方法里有一个输出消息 -->
        <wsdl:output name="APNMResponse" message="tns:APNMResponse"/>
        <!--fault 方法里有一个错误消息 -->
        <wsdl:fault name="FaultMessage" message="tns:FaultMessage"/>
    </wsdl:operation>
</wsdl:portType>

portType 相当于一个类。

operation 相当于该类里有一个方法名,方法名为processAPNManagement,该方法里有一个输入消息,一个输出消息,一个错误消息。

WSDL 消息

元素定义一个操作的数据元素。每个消息可以传递一个或者多个参数。

(二)WSDL types

元素定义 web service 使用的数据类型。为了最大程度的平台中立性,WSDL 使用 XML Schema 语法来定义数据类型。即定义了各种参数(请求和返回的各种参数的数据类型定义)。

(三)WSDL Bindings

binding 元素有两个属性 - name 属性和 type 属性。name 属性定义 binding 的名称,而 type 属性指向用于 binding 的端口,在这个例子中是 “tns:PAPNManagementPortType” 端口。

soap:binding 元素有两个属性 - style 属性和 transport 属性。style 属性可取值 “rpc” 或 “document”。transport 属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP。

style 属性可取值 “rpc” 或 “document”。rpc是远程过程调用约定。使用文档document样式时,客户端知道应该使用 XML模式。transport 属性定义了要使用的 SOAP 协议。WSDL 规范通常描述三种绑定扩展:HTTP GET/POST、MIME 以及 SOAP version 1.1。HTTP GET/POST 和 MIME 中定义的绑定扩展用来定义与标准的 Web 应用程序进行通信的需求,这些应用程序可能返回(也可能不返回)XML 文档。在发送或返回 XML 文档时,HTTP GET/POST 绑定的扩展是隐式的文档样式。

operation 元素定义了每个端口提供的操作符。不管soap:binding元素中的声明如何,soap:operation元素可以覆盖每个操作的声明,对于每个操作,相应的 SOAP 行为都需要被定义。同时您必须如何对输入和输出进行编码。在这个例子中我们使用了 “literal”。

三、如何看一个完整的WSDL文档

首先,WSDL文档最开始应该从下往上看,这一比较容易。

例子:

<?xml version="1.0" encoding="UTF-8"?>
<!--  WSDL 端口类型  -->
<!-- 目标名称空间 目标命名空间一定是有效的,其他命名空间不一定有效。-->
<wsdl:definitions name="PAPNManagementPortType"
                  targetNamespace="http://gg.ericsson.com/PAPNManagementPortType/"
                  xmlns:ns="http://schemas.xmlsoap.org/soap/encoding/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:tns="http://gg.ericsson.com/PAPNManagementPortType/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 			xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xs:schema attributeFormDefault="unqualified"
        elementFormDefault="unqualified"
        targetNamespace="http://gg.ericsson.com/PAPNManagementPortType/"
        xmlns:tns="http://gg.ericsson.com/PAPNManagementPortType/"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- 3.3:找到message中对应 复杂类型complexType  APNMRequest-APNMRequestType sequence 下的元素element为传入的参数和参数类型--->
<xs:element name="APNMRequest" type="tns:APNMRequest" />
<xs:element name="APNMResponse" type="tns:APNMResponse" />
<xs:element name="FaultMessage" type="tns:FaultMessage" />
<xs:complexType name="APNMRequest">
    <xs:sequence>
   		<xs:element name="Request" type="tns:APNMRequestType" />
    </xs:sequence>
</xs:complexType>
<xs:complexType name="APNMRequestType">
    <xs:sequence>
        <xs:element name="MSISDN" type="xs:string" />
        <xs:element name="APN_Type" type="xs:string" />
        <xs:element name="Transaction_Type" type="xs:string" />
        <xs:element name="Request_ID" type="xs:string" />
        <xs:element name="Request_Date_Time" type="xs:string" />
    </xs:sequence>
</xs:complexType>
<!-- 4.3:找到tyeps节点下name属性值为APNMResponse的element节点 
其返回的类型即为APNMResponseType类型文件。该文件的结构在命名空间xmlns:tns中APNMResponseType元素中  在此例子中,该命名空间指向本文件。即返回APNMResponseType中的三个参数,该三个参数包装在一个对象中,即返回一个对象。-->
<xs:complexType name="APNMResponse">
<xs:sequence>
	<xs:element name="Request" type="tns:APNMResponseType" />
</xs:sequence>
</xs:complexType>
    <xs:complexType name="APNMResponseType">
    <xs:sequence>
        <xs:element name="Result_Code" type="xs:string" />
        <xs:element name="Result_Date_Time" type="xs:string" />
        <xs:element name="Result_Description" type="xs:string" />
    </xs:sequence>
</xs:complexType>
<xs:complexType name="FaultMessage">
    <xs:sequence>
        <xs:element minOccurs="0" name="FaultCode" type="xs:integer" />
        <xs:element minOccurs="0" name="FaultMessage" type="xs:string" />
        <xs:element minOccurs="0" name="FaultActor" type="xs:string" />
        <xs:element minOccurs="0" name="FaultDetail" type="xs:string" />
    </xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
    <!-- 3.2:找出这个porttype中operation中的input指向的message节点  -->
	<!-- 4.2:找出这个porttype中operation中的output指向的message节点 -->
<wsdl:message name="APNMResponse">
    <wsdl:part name="parameters" element="tns:APNMResponse" />
</wsdl:message>
<wsdl:message name="FaultMessage">
    <wsdl:part name="parameters" element="tns:FaultMessage" />
</wsdl:message>
    <wsdl:message name="APNMRequest">
    <wsdl:part name="parameters" element="tns:APNMRequest" />
</wsdl:message>
<!-- 第二步:确定接口中都有哪些方法以及方法的名称:processAPNManagement   一个operation节点就代表一个方法,也就是在接口中声明几个方法。-->
<!-- 第三步:确定接口中方法的参数类型,顺序  portType  PAPNManagementPortType 
    假设我要找processAPNManagement方法的参数类型和顺序;
   3.1:找出binding节点对应的porttype节点
     根据binding节点为tns:PAPNManagementPortType,找出porttype节点PAPNManagementPortType-->
     <!-- 第四步:找出这个服务类中方法的返回值类型 
    4.1:找出这个方法所在的porttype节点 PAPNManagementPortType  -->
<wsdl:portType name="PAPNManagementPortType">
<!-- 2:找出porttype中每一个operation中的input和output对应的message -->
<wsdl:operation name="processAPNManagement">
    <wsdl:input name="APNMRequest" message="tns:APNMRequest" />
    <wsdl:output name="APNMResponse" message="tns:APNMResponse" />
    <wsdl:fault name="FaultMessage" message="tns:FaultMessage" />
</wsdl:operation>
</wsdl:portType>
    <wsdl:binding name="PAPNMServiceSoapBinding"
    type="tns:PAPNManagementPortType">
    <soap:binding style="document"
    transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="processAPNManagement">
<soap:operation style="document" />
    <wsdl:input>
    	<soap:body use="literal" />
    </wsdl:input>
    <wsdl:output>
    	<soap:body use="literal" />
    </wsdl:output>
    <wsdl:fault name="FaultMessage">
    	<soap:fault name="FaultMessage" use="literal" />
    </wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<!-- 第一步:确定接口的名称:ProcessAPNManagementService -->
<wsdl:service name="ProcessAPNManagementService">
    <wsdl:port name="ProcessAPNManagementPort" binding="tns:PAPNMServiceSoapBinding">
    <!-- 第五步:确定对外提供服务的url地址 
         这里的url的第一级目录和二级目录会影响我们的配置;
			一级目录影响的是:web.xml中监听器的匹配规则
			二级目录影响的是:注册webservice服务的时候指定的名称-->
        <soap:address location="http://localhost:8080/LIG_cxf/services/ProcessAPNManagementPort" />
    </wsdl:port>
</wsdl:service>
</wsdl:definitions>

第一步:确定接口的名称:wsdl:service name=“ProcessAPNManagementService”

第二步:确定接口中都有哪些方法以及方法的名称:processAPNManagement 一个operation节点就代表一个方法,也就是在接口中声明几个方法。

第三步:确定接口中方法的参数类型和顺序 portType PAPNManagementPortType

假设我要找processAPNManagement方法的参数类型和顺序;

3.1:找出binding节点对应的vporttype节点,根据binding节点为tns:PAPNManagementPortType,找出端口porttype节点PAPNManagementPortType

3.2:找出这个porttype中operation中的input指向的message节点

3.3.:找到message中对应 复杂类型complexType APNMRequest-APNMRequestType sequence 下的元素element为传入的参数和参数类型

第四步:找出这个服务类中方法的返回值类型

4.1:找出这个方法所在的porttype节点 PAPNManagementPortType

4.2:找出porttype中每一个operation中的input和output对应的message

4.3:找到tyeps节点下name属性值为APNMResponse的element节点

其返回的类型即为APNMResponseType类型文件。该文件的结构在命名空间xmlns:tns中APNMResponseType元素中 在此例子中,该命名空间指向本文件。即返回APNMResponseType中的三个参数,该三个参数包装在一个对象中,即返回一个对象。

第五步:确定对外提供服务的url地址

这里的url的第一级目录和二级目录会影响我们的配置;

​ 一级目录影响的是:web.xml中监听器的匹配规则

​ 二级目录影响的是:注册webservice服务的时候指定的名称

  • 8
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值