`
kong_bai
  • 浏览: 136617 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

WSDL解析

阅读更多
以下是开发webservice采用wsdl-first开发模式的一个wsdl例子(摘自CXF example),一个wsdl的编写必须由5小节元素构成:



<?xml version="1.0" encoding="utf-8"?>
<!--wsdl根元素definitions,同时使用xmlns:xxx对各命名空间进行缩写,方便引用-->
<wsdl:definitions name="SOAPBuilders-mime-cr-test" xmlns:types="http://cxf.apache.org/mime/types"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://cxf.apache.org/mime"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:xmime="http://www.w3.org/2005/05/xmlmime"   
    targetNamespace="http://cxf.apache.org/mime">

    <!--第一节types元素:主要是使用schema对webservice组件的方法参数和返回值进行类型定义,类似于java的编写class-->
    <wsdl:types>
        <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cxf.apache.org/mime/types"
            xmlns:xmime="http://www.w3.org/2005/05/xmlmime" elementFormDefault="qualified">
            <complexType name="ByteArrayType">
                <sequence>
                    <element name="name" type="xsd:string" />
                    <element name="attachinfo" type="xsd:base64Binary"/>
                </sequence>
            </complexType>
            <element name="testByteArray" type="types:ByteArrayType" />
            <element name="testByteArrayResponse" type="types:ByteArrayType" />
           
            <complexType name="DataHandlerType">
                <sequence>
                    <element name="name" type="xsd:string" />
                    <element name="attachinfo" type="xsd:base64Binary"
                             xmime:expectedContentTypes="application/octet-stream"/>
                </sequence>
            </complexType>
            <element name="testDataHandler" type="types:DataHandlerType" />
            <element name="testDataHandlerResponse" type="types:DataHandlerType" />
        </schema>

    </wsdl:types>


<!--第二节message元素:主要是引用第一节的类型定义来创建webservice组件的方法参数和返回值元素,类似于java创建类的实例-->
    <wsdl:message name="testByteArrayIn">
        <wsdl:part name="data" element="types:testByteArray" />
    </wsdl:message>

    <wsdl:message name="testByteArrayOut">
        <wsdl:part name="data" element="types:testByteArrayResponse" />
    </wsdl:message>


    <wsdl:message name="testDataHandlerIn">
        <wsdl:part name="data" element="types:testDataHandler" />
    </wsdl:message>

    <wsdl:message name="testDataHandlerOut">
        <wsdl:part name="data" element="types:testDataHandlerResponse" />
    </wsdl:message>


<!--第三节portType元素:定义了webservice组件的方法名、参数和返回值元素-->
    <wsdl:portType name="TestMtomPortType">
        <wsdl:operation name="testByteArray">
            <wsdl:input message="tns:testByteArrayIn" />
            <wsdl:output message="tns:testByteArrayOut" />
        </wsdl:operation>

        <wsdl:operation name="testDataHandler">
            <wsdl:input message="tns:testDataHandlerIn" />
            <wsdl:output message="tns:testDataHandlerOut" />
        </wsdl:operation>
    </wsdl:portType>

<!--第四节bingding元素:定义了底层的传输协议是基于http还是别的协议,同时指定绑定模式是rpc/encode还是document/literal等模式-->
    <wsdl:binding name="TestMtomBinding" type="tns:TestMtomPortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />

        <wsdl:operation name="testByteArray">
            <soap:operation soapAction="" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>

        <wsdl:operation name="testDataHandler">
            <soap:operation soapAction="" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>

    </wsdl:binding>

<!--第五节service元素,定义了发布的组件服务名和端口地址-->
    <wsdl:service name="TestMtomService">
        <wsdl:port name="TestMtomPort" binding="tns:TestMtomBinding">
            <soap:address location="http://localhost:9000/mime-test" />
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

分享到:
评论
1 楼 kong_bai 2009-04-10  
WSDL Web 服务描述语言。
WSDL 用 XML 写。
WSDL 是一个 XML 文档。
WSDL 用来描述 Web 服务。
WSDL 用来定位 Web 服务。
WSDL 仍然不是 W3C 标准。

相关推荐

Global site tag (gtag.js) - Google Analytics