WSDL 学习(一)

进行了和Web Service相关的开发这么多年,或多或少地和WSDL邂逅过,但是对WSDL的了解还是莫里两可,所以称国庆这么一点时间,来整理一下。

 

在开始之前,我们先看一个最基本的,完整的wsdl文档定义是什么样子。

HelloWorld1.wsdl

xml version="1.0" encoding="utf-8" ?>

 

 

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

 

 

             targetNamespace="http://tempuri.org/helloworld.wsdl"

 

 

             xmlns:tns="http://tempuri.org/helloworld.wsdl"

 

 

             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

 

 

                  xmlns="http://tempuri.org/helloworld.wsdl"

 

 

                  xmlns:t="http://tempuri.org/types"

 

 

             >

 

 

  <wsdl:types>

 

 

    <wsdl:documentation>types of the wsdl</wsdl:documentation>

 

 

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/types">

 

 

      <xs:element name="MyRequest">

 

 

        <xs:complexType>

 

 

          <xs:sequence>

 

 

            <xs:element name="Data" type="xs:string" minOccurs="1" maxOccurs="1"/>

 

 

            <xs:element name="Number" type="xs:int" minOccurs="1" maxOccurs="1"/>

 

 

            <xs:element name="DateTime" type="xs:dateTime" minOccurs="1" maxOccurs="1"/>

 

 

          </xs:sequence>

 

 

        </xs:complexType>

 

 

      </xs:element>

 

 

      <xs:element name="MyResponse">

 

 

        <xs:complexType>

 

 

          <xs:sequence>

 

 

            <xs:element name="Data" type="xs:string" minOccurs="1" maxOccurs="1"/>

 

 

          </xs:sequence>

 

 

        </xs:complexType>

 

 

      </xs:element>

 

 

    </xs:schema>

 

 

  </wsdl:types>

 

 

 

 

 

  <wsdl:message name="HelloWorldInputMessage">

 

 

    <wsdl:part name="body" element="t:MyRequest"/>

 

 

  </wsdl:message>

 

 

  <wsdl:message name="HelloWorldOutputMessage">

 

 

    <wsdl:part name="body" element="t:MyResponse"/>

 

 

  wsdl:message>

 

 

 

 

 

  <wsdl:portType name="HelloWorldPortType">

 

 

    <wsdl:operation name="HelloWorld">

 

 

      <wsdl:input message="tns:HelloWorldInputMessage"/>

 

 

      <wsdl:output message="tns:HelloWorldOutputMessage"/>

 

 

    </wsdl:operation>

 

 

  </wsdl:portType>

 

 

 

 

 

  <wsdl:binding name ="HelloWorldBinding" type="tns:HelloWorldPortType">

 

 

    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

 

 

    <wsdl:operation name="HelloWorld">

 

 

      <soap:operation soapAction="http://tempuri.org/HelloWorld"/>

 

 

      <wsdl:input>

 

 

        <soap:body use="literal"/>

 

 

      </wsdl:input>

 

 

      <wsdl:output>

 

 

        <soap:body use="literal"/>

 

 

      </wsdl:output>

 

 

    </wsdl:operation>

 

 

  </wsdl:binding>

 

 

 

 

 

  <wsdl:service name="HelloWorldService">

 

 

    <wsdl:port name="SPort" binding="tns:HelloWorldBinding">

 

 

      <soap:address location="http://tempuri.org"/>

 

 

    </wsdl:port>

 

 

  </wsdl:service>

 

 

 

 

 

</wsdl:definitions>

 

从上面的例子可以看出,WSDL文档由4种类型组成

  1. Type
  2. Message
  3. PortType
  4. Binding
  5. Service

(当然,我这里的划分,和w3中的划分不一致,大家可以同时参考w3的划分)

其中1,2,3是抽象定义,和任何具体的实现都无关;4,5是抽象定义的实现。

而4是将前面的抽象定义和具体的传输协议(protocol)以及传输的数据格式(data format)联系起来。

而5是将4和具体的地址(address)联系起来。

所以,根据上面的分析,在具体的实践中,为了达到重用的目的,通常的wsdl文档由多个文档组成。

Type的定义放在*.xsd文档中,Message和PortType的定义放在*.wsdl文档中,Binding的定义放在*.wsdl文档中,Service的定义放在*.wsdl文档中。

 

以上描述的是wsdl的一个初步轮廓,上面的知识可以帮助你完成一个wsdl的定义,并将其用于web service开发,但wsdl的内容却不仅限于此。

对wsdl描述的理解不知是用于web service的开发,其最终目标是解决跨平台服务通信的问题(网上有很多这类问题的求助)。

 

 

我也是在学习中,更深入的内容我会整理后贴出来。希望能够和大家更多的交流。

 

更多内容,请转向我的Blog导读

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

明天好,会的

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值