webservice 之 WSDL的解析

 

先看一个wsdl, 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:tns="http://ws.lk.com"
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.lk.com">
    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            attributeFormDefault="qualified" elementFormDefault="qualified"
            targetNamespace="http://ws.lk.com">
            <xsd:element name="example">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element maxOccurs="1" minOccurs="1" name="in0"
                            nillable="true" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="exampleResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element maxOccurs="1" minOccurs="1" name="out"
                            nillable="true" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="exampleRequest">
        <wsdl:part name="parameters" element="tns:example"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="exampleResponse">
        <wsdl:part name="parameters" element="tns:exampleResponse"></wsdl:part>
    </wsdl:message>
    <wsdl:portType name="HelloWSsssPortType">
        <wsdl:operation name="example">
            <wsdl:input name="exampleRequest" message="tns:exampleRequest"></wsdl:input>
            <wsdl:output name="exampleResponse" message="tns:exampleResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="HelloWSsssHttpBinding" type="tns:HelloWSsssPortType">
        <wsdlsoap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="example">
            <wsdlsoap:operation soapAction="" />
            <wsdl:input name="exampleRequest">
                <wsdlsoap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="exampleResponse">
                <wsdlsoap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="HelloWSsss">
        <wsdl:port name="HelloWSsssHttpPort" binding="tns:HelloWSsssHttpBinding">
            <wsdlsoap:address location="http://localhost:8080/HelloWS/services/HelloWSsss" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

首先通过MyEclipse 的 New web service 向导生成java代码,可以同时生成接口、实现类,然后访问http://localhost:8080/HelloWS/services/HelloWSsss?wsdl 得到的。

如果通过MyEclipse 的 MyEclipse WSDL Editor打开,则得到:

 

类似这样的图片,看到个很多次了,每次都是看不懂。。。 郁闷。 不过,其实要是稍微研究对应的.wsdl一下,则发现,它没那么的吓人。

基本结构就是:

wsdl:service  有wsdl:port 的子元素,wsdl:port 有子元素wsdlsoap:address 提供对外访问的url。 wsdl:port 同时由binding属性绑定了一个wsdl:binding 。

wsdl:binding 有type属性指定了wsdl:portType  ,wsdl:portType  包含子元素wsdl:operation ,wsdl:operation 的name属性指定了其对外提供的方法。

子元素wsdl:input 、wsdl:output  分部对应方法的参数、返回值。wsdl:input 、wsdl:output 的message属性指定了wsdl:message ,子元素wsdl:part 的element属性指定了

包含在wsdl:types中的xsd:element ,xsd:element 子子元素的type属性指定了 具体的数据类型。

 

这样的描述显得混乱,但是我不太会通过绘图来分析。先这样吧。

 

规律:

如果是通过New web service 向导生成的, 默认的各元素属性名字,非常有规律:

假设 ws 名字为 

HelloWSsss ,那么 ——> binding="tns:HelloWSsssHttpBinding" -> type="tns:HelloWSsssPortType" -> wsdl:operation name="example"
兵分两路:
-> wsdl:input name="exampleRequest" -> element="tns:example"
-> wsdl:output name="exampleResponse" -> element="tns:exampleResponse"

__ 就这样,注意到, input参数message名 为 exampleRequest ,到了element标签的时候,名字重新变回了 example, 当然,这个无关紧要,非常小的细节。。。

 

xsd:element -> wsdl:message  -> wsdl:portType  : wsdl:operation  -> input 、 output 两个 wsdl:message  -> 两个 xsd:element 

 

 

不搞了,反正已经完全不惧怕wsdl了!!

 

看到那样的图,也完全不用担心看不懂了! 其实很简单,只是wsdl 这样的格式把一个非常简单的ws描述的复杂起来,当然,这也可能是为了能够处理复杂问题,而逐渐完善起来的规范。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值