微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WebService 学习3

WSDL

WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问。

WSDL 文档结构

元素 定义
<portType> web service 执行的操作
<message> web service 使用的消息
<types> web service 使用的数据类型
<binding> web service 使用的通信协议

基本格式:
<deFinitions>

<types>
   deFinition of types........
</types>

<message>
   deFinition of a message....
</message>

<portType>
   deFinition of a port.......
</portType>

<binding>
   deFinition of a binding....
</binding>

</deFinitions>

示例:



WSDL 端口

<portType> 元素是最重要的 WSDL 元素。它可描述一个 web service、可被执行的操作,以及相关的消息。可以把 <portType> 元素比作传统编程语言中的一个函数库(或一个模块、或一个类)。

操作类型

类型
定义
One-way 此操作可接受消息,但不会返回响应。
Request-response 此操作可接受一个请求并会返回一个响应
Solicit-response 此操作可发送一个请求,并会等待一个响应。
Notification 此操作可发送一条消息,但不会等待响应。



WSDL 消息

<message> 元素定义一个操作的数据元素。每个消息均由一个或多个部件组成。可以把这些部件比作传统编程语言中一个函数调用的参数。



WSDL types

<types> 元素定义 web service 使用的数据类型。为了最大程度的平台中立性,WSDL 使用 XML Schema 语法来定义数据类型。



WSDL Bindings

<binding> 元素为每个端口定义消息格式和协议细节。


完整的WSDL实例:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:deFinitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://person.service.yang" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax21="http://person.service.yang/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://person.service.yang">
    <wsdl:documentation>PersonService</wsdl:documentation>
    <wsdl:types>
        <xs:schema xmlns:ax22="http://person.service.yang/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://person.service.yang">
            <xs:import namespace="http://person.service.yang/xsd"/>
            <xs:element name="UpdatePersonByNum">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="num" type="xs:int"/>
                        <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
                        <xs:element minOccurs="0" name="sex" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="UpdatePersonByNumResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax21:Person"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="Queryall">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="query" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="QueryallResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax21:Person"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="QueryPersonByNum">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="num" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="QueryPersonByNumResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax21:Person"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="QueryPersonByName">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="QueryPersonByNameResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax21:Person"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="DelPersonByNum">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="num" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="DelPersonByNumResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="DelPersonAll">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="del" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="DelPersonAllResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="AddPerson">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="num" type="xs:int"/>
                        <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
                        <xs:element minOccurs="0" name="sex" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="AddPersonResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax21:Person"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
        <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://person.service.yang/xsd">
            <xs:complexType name="Person">
                <xs:sequence>
                    <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="num" type="xs:int"/>
                    <xs:element minOccurs="0" name="sex" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="QueryallRequest">
        <wsdl:part name="parameters" element="ns:Queryall"/>
    </wsdl:message>
    <wsdl:message name="QueryallResponse">
        <wsdl:part name="parameters" element="ns:QueryallResponse"/>
    </wsdl:message>
    <wsdl:message name="DelPersonAllRequest">
        <wsdl:part name="parameters" element="ns:DelPersonAll"/>
    </wsdl:message>
    <wsdl:message name="DelPersonAllResponse">
        <wsdl:part name="parameters" element="ns:DelPersonAllResponse"/>
    </wsdl:message>
    <wsdl:message name="DelPersonByNumRequest">
        <wsdl:part name="parameters" element="ns:DelPersonByNum"/>
    </wsdl:message>
    <wsdl:message name="DelPersonByNumResponse">
        <wsdl:part name="parameters" element="ns:DelPersonByNumResponse"/>
    </wsdl:message>
    <wsdl:message name="QueryPersonByNameRequest">
        <wsdl:part name="parameters" element="ns:QueryPersonByName"/>
    </wsdl:message>
    <wsdl:message name="QueryPersonByNameResponse">
        <wsdl:part name="parameters" element="ns:QueryPersonByNameResponse"/>
    </wsdl:message>
    <wsdl:message name="AddPersonRequest">
        <wsdl:part name="parameters" element="ns:AddPerson"/>
    </wsdl:message>
    <wsdl:message name="AddPersonResponse">
        <wsdl:part name="parameters" element="ns:AddPersonResponse"/>
    </wsdl:message>
    <wsdl:message name="QueryPersonByNumRequest">
        <wsdl:part name="parameters" element="ns:QueryPersonByNum"/>
    </wsdl:message>
    <wsdl:message name="QueryPersonByNumResponse">
        <wsdl:part name="parameters" element="ns:QueryPersonByNumResponse"/>
    </wsdl:message>
    <wsdl:message name="UpdatePersonByNumRequest">
        <wsdl:part name="parameters" element="ns:UpdatePersonByNum"/>
    </wsdl:message>
    <wsdl:message name="UpdatePersonByNumResponse">
        <wsdl:part name="parameters" element="ns:UpdatePersonByNumResponse"/>
    </wsdl:message>
    <wsdl:portType name="PersonServicePortType">
        <wsdl:operation name="Queryall">
            <wsdl:input message="ns:QueryallRequest" wsaw:Action="urn:Queryall"/>
            <wsdl:output message="ns:QueryallResponse" wsaw:Action="urn:QueryallResponse"/>
        </wsdl:operation>
        <wsdl:operation name="DelPersonAll">
            <wsdl:input message="ns:DelPersonAllRequest" wsaw:Action="urn:DelPersonAll"/>
            <wsdl:output message="ns:DelPersonAllResponse" wsaw:Action="urn:DelPersonAllResponse"/>
        </wsdl:operation>
        <wsdl:operation name="DelPersonByNum">
            <wsdl:input message="ns:DelPersonByNumRequest" wsaw:Action="urn:DelPersonByNum"/>
            <wsdl:output message="ns:DelPersonByNumResponse" wsaw:Action="urn:DelPersonByNumResponse"/>
        </wsdl:operation>
        <wsdl:operation name="QueryPersonByName">
            <wsdl:input message="ns:QueryPersonByNameRequest" wsaw:Action="urn:QueryPersonByName"/>
            <wsdl:output message="ns:QueryPersonByNameResponse" wsaw:Action="urn:QueryPersonByNameResponse"/>
        </wsdl:operation>
        <wsdl:operation name="AddPerson">
            <wsdl:input message="ns:AddPersonRequest" wsaw:Action="urn:AddPerson"/>
            <wsdl:output message="ns:AddPersonResponse" wsaw:Action="urn:AddPersonResponse"/>
        </wsdl:operation>
        <wsdl:operation name="QueryPersonByNum">
            <wsdl:input message="ns:QueryPersonByNumRequest" wsaw:Action="urn:QueryPersonByNum"/>
            <wsdl:output message="ns:QueryPersonByNumResponse" wsaw:Action="urn:QueryPersonByNumResponse"/>
        </wsdl:operation>
        <wsdl:operation name="UpdatePersonByNum">
            <wsdl:input message="ns:UpdatePersonByNumRequest" wsaw:Action="urn:UpdatePersonByNum"/>
            <wsdl:output message="ns:UpdatePersonByNumResponse" wsaw:Action="urn:UpdatePersonByNumResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="PersonServiceSoap11Binding" type="ns:PersonServicePortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="Queryall">
            <soap:operation soapAction="urn:Queryall" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="DelPersonAll">
            <soap:operation soapAction="urn:DelPersonAll" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="DelPersonByNum">
            <soap:operation soapAction="urn:DelPersonByNum" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="QueryPersonByName">
            <soap:operation soapAction="urn:QueryPersonByName" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="AddPerson">
            <soap:operation soapAction="urn:AddPerson" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="QueryPersonByNum">
            <soap:operation soapAction="urn:QueryPersonByNum" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="UpdatePersonByNum">
            <soap:operation soapAction="urn:UpdatePersonByNum" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="PersonServiceSoap12Binding" type="ns:PersonServicePortType">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="Queryall">
            <soap12:operation soapAction="urn:Queryall" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="DelPersonAll">
            <soap12:operation soapAction="urn:DelPersonAll" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="DelPersonByNum">
            <soap12:operation soapAction="urn:DelPersonByNum" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="QueryPersonByName">
            <soap12:operation soapAction="urn:QueryPersonByName" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="AddPerson">
            <soap12:operation soapAction="urn:AddPerson" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="QueryPersonByNum">
            <soap12:operation soapAction="urn:QueryPersonByNum" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="UpdatePersonByNum">
            <soap12:operation soapAction="urn:UpdatePersonByNum" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="PersonServiceHttpBinding" type="ns:PersonServicePortType">
        <http:binding verb="POST"/>
        <wsdl:operation name="Queryall">
            <http:operation location="Queryall"/>
            <wsdl:input>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="DelPersonAll">
            <http:operation location="DelPersonAll"/>
            <wsdl:input>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="DelPersonByNum">
            <http:operation location="DelPersonByNum"/>
            <wsdl:input>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="QueryPersonByName">
            <http:operation location="QueryPersonByName"/>
            <wsdl:input>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="AddPerson">
            <http:operation location="AddPerson"/>
            <wsdl:input>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="QueryPersonByNum">
            <http:operation location="QueryPersonByNum"/>
            <wsdl:input>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="UpdatePersonByNum">
            <http:operation location="UpdatePersonByNum"/>
            <wsdl:input>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="parameters"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="PersonService">
        <wsdl:port name="PersonServiceHttpSoap11Endpoint" binding="ns:PersonServiceSoap11Binding">
            <soap:address location="http://localhost:8080/axis2/services/PersonService.PersonServiceHttpSoap11Endpoint/"/>
        </wsdl:port>
        <wsdl:port name="PersonServiceHttpSoap12Endpoint" binding="ns:PersonServiceSoap12Binding">
            <soap12:address location="http://localhost:8080/axis2/services/PersonService.PersonServiceHttpSoap12Endpoint/"/>
        </wsdl:port>
        <wsdl:port name="PersonServiceHttpEndpoint" binding="ns:PersonServiceHttpBinding">
            <http:address location="http://localhost:8080/axis2/services/PersonService.PersonServiceHttpEndpoint/"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:deFinitions>
自己发布的Webservice,并不一定符合标准规范,仅供参考

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐