zoukankan      html  css  js  c++  java
  • wsdl学习

    本文来自 :迹忆 原文地址:http://www.onmpw.com/tm/xwzj/network_47.html

      在刚开始学习Webservice的时候,发现里面涉及到的知识点还真不少,每一点单拿出来都可以自成一派了。尤其是看到WSDL的时候,查了很长时间的资料,依然是有些迷惑,对其没有一个清晰的认识。随着在以后的工作中,自己写了一些WSDL的案例,才逐渐的对其内部原理有了一些认识。

      首先先看一下WSDL的作用:WSDL(Web Service Description Language)用XML格式的文件来描述可用的Web服务。其实说白了就是一个标准,终端按照这个标准在网络中创建Web服务,客户端也按照此标准去连接这个服务,并且根据WSDL文件获知自己所需要的操作。

      接下来我想说一下WSDL的发展过程,了解WSDL的产生历史,在以后的学习过程中不至于产生迷惑。

      WSDL的第一个版本是WSDL1.0 在2000年9月有IBM,Microsoft以及Ariba开发,目的就是描述Web Service 的SOAP工具包。随后在2001年3月,WSDL 1.1版本发布,此举标志着WSDL走向了正轨。但是在1.0 和1.1之间并没有产生多大的变化。时隔两年,在2003年6月最为W3C的工作草案 WSDL1.2发布。按照W3C的说法,WSDL1.2相对于1.1版本来说开发者使用起来更简单并且更灵活了。但是WSDL1.2并不支持大多数的SOAP服务。在2007年6月,WSDL1.2被正式更名为WSDL2.0,此时WSDL2.0也成为了W3C的推荐版本。做出这一改变的原因是2.0版本相对于1.1版本来说有了实质性的改变,所以上升了一个等级。所以说现在WSDL流行的两个版本是WSDL2.0 和 WSDL1.1。虽说WSDL2.0 是W3C推荐的版本,但是现在大多数的厂商支持的还是WSDL1.1。举个例子来说,我们都知道PHP的一款官方IDE——zendstudio还有java IDE——Eclipse,当我们使用它们新建WSDl文件时,这个WSDl文件所遵循的格式还是WSDL1.1版本的格式。在我平时的工作中,使用的WSDL也是遵循的1.1版本的格式。

      那WSDL1.1和WSDL2.0的格式究竟是怎样的呢,下面我来向大家介绍介绍。

      首先我们看一下WSDL1.1,按照此标准,在WSDL文件中包含下面七项内容

    1. Types

      可以认为是一个容器,容器里的内容是数据类型的描述,当然需要借助于XML Schema 来达到这一目的。那么这个容器的格式如下

     1 <wsdl:types>
     2     <xsd:schema targetNamespace="http://www.test.com/WSDLFile/">
     3       <xsd:element name="Operation">
     4         <xsd:complexType>
     5           <xsd:sequence>
     6             <xsd:element name="in" type="xsd:string"/>
     7           </xsd:sequence>
     8         </xsd:complexType>
     9       </xsd:element>
    10       <xsd:element name="OperationResponse">
    11         <xsd:complexType>
    12           <xsd:sequence>
    13             <xsd:element name="out" type="xsd:string"/>
    14           </xsd:sequence>
    15         </xsd:complexType>
    16       </xsd:element>
    17     </xsd:schema>
    18   </wsdl:types>

    2. Message

    对操作接口进行一个抽象的定义。格式如下:

    1 <wsdl:message name="OperationRequest">
    2     <wsdl:part element="tns:Operation" name="parameters"/>
    3   </wsdl:message>
    4 <wsdl:message name="OperationResponse">
    5     <wsdl:part element="tns:OperationResponse" name="parameters"/>
    6   </wsdl:message>

    Messages包含了一个或者多个part 元素,对于Message的属性name的值是唯一的,和当前整个WSDL文件中的人和一个Message的name值都不能相同。Part的属性name的值也是唯一的,和当前Message中的其它的任何一个part的name的值都不能相同,当然处于不同的Message中的part的name的值可以相同。

    每一个part元素都关联message-type属性,这个message-type属性一般包含两部分:element和type。Message中的每一个part对应Types中的一个element元素,并且part的element属性的值为 Types中的element的name的值,前面再加上tns: ,举例如下(下面的代码是摘自 http://www.w3.org/TR/wsdl#_introduction):

     1 <types>
     2         <schema .... >
     3            <element name="PO" type="tns:POType"/>
     4            <complexType name="POType">
     5                <all>
     6                    <element name="id" type="string/>
     7                    <element name="name" type="string"/>
     8                    <element name="items">
     9                        <complexType>
    10                            <all>
    11                                <element name="item" type="tns:Item" minOccurs="0" maxOccurs="unbounded"/>
    12                            </all>
    13                        </complexType>
    14                    </element>
    15               </all>
    16            </complexType>
    17  
    18            <complexType name="Item">
    19                <all>
    20                    <element name="quantity" type="int"/>
    21                    <element name="product" type="string"/>
    22                </all>
    23            </complexType>
    24            <element name="Invoice" type="tns:InvoiceType"/>
    25            <complexType name="InvoiceType">
    26                <all>
    27                    <element name="id" type="string"/>
    28                </all>
    29            </complexType>
    30         </schema>
    31     </types>
    32 <message name="PO">
    33         <part name="po" element="tns:PO"/>
    34         <part name="invoice" element="tns:Invoice"/>
    35     </message>

    对于Message这一项在WSDL2.0中已经去掉了。

    3. Port Type

    由终端定义的一系列的抽象方法,其格式如下  

    1 <wsdl:portType name="WSDLFile">
    2     <wsdl:operation name="Operation">
    3       <wsdl:input message="tns:OperationRequest"/>
    4       <wsdl:output message="tns:OperationResponse"/>
    5     </wsdl:operation>
    6 </wsdl:portType>
  • 相关阅读:
    Python元组、列表、字典
    测试通过Word直接发布博文
    Python环境搭建(windows)
    hdu 4003 Find Metal Mineral 树形DP
    poj 1986 Distance Queries LCA
    poj 1470 Closest Common Ancestors LCA
    poj 1330 Nearest Common Ancestors LCA
    hdu 3046 Pleasant sheep and big big wolf 最小割
    poj 3281 Dining 最大流
    zoj 2760 How Many Shortest Path 最大流
  • 原文地址:https://www.cnblogs.com/xiayahui/p/5659415.html
Copyright © 2011-2022 走看看