Webservice学习之WSDL详解

1. <definitions/>web

这部分在基础篇里已经介绍,主要说明引用了哪些schema以及schema的位置等,能够看下基础篇的介绍,SayHello的Demo这部份内容以下:编程

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.service.server.ws.devins.com/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http"
    xmlns:ns1="http://service.server.ws.devins.com/" name="SayHelloImplService"
    targetNamespace="http://impl.service.server.ws.devins.com/">

2. <types/>服务器

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

         <!-- 
          types
          schema:约束xml格式
          element:用来指定xml中的标签
                  <sayHello></sayhello>
                  <sayHelloResponse></sayHelloResponse>
          complexType:说明是一个复合类型
                           请求 
                   <sayHello>
                       <arg0>string</arg0>
                   </sayhello>
                     响应
                   <sayHelloResponse>
                       <return>string</return>
                   </sayHelloResponse>
                   
        回看下demo的请求与响应的核心内容
             <q0:sayHello>
              <arg0>devins</arg0> 
            </q0:sayHello>
            
            <ns2:sayHelloResponse">
              <return>Hello: devins</return> 
            </ns2:sayHelloResponse>
                  
      -->
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://service.server.ws.devins.com/" elementFormDefault="unqualified"
            targetNamespace="http://service.server.ws.devins.com/" version="1.0">
            <xs:element name="sayHello" type="tns:sayHello" />
            <xs:element name="sayHelloResponse" type="tns:sayHelloResponse" />
            <xs:complexType name="sayHello">
                <xs:sequence>
                    <xs:element minOccurs="0" name="arg0" type="xs:string" />
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="sayHelloResponse">
                <xs:sequence>
                    <xs:element minOccurs="0" name="return" type="xs:string" />
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>

3. <message/>函数

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

        <!-- 
        message:用来定义soap消息结构
        part:部分/组成的意思
        实际上引用的就是上面schema中的约束格式
     -->
    <wsdl:message name="sayHelloResponse">
        <wsdl:part element="ns1:sayHelloResponse" name="parameters" />
    </wsdl:message>
    <wsdl:message name="sayHello">
        <wsdl:part element="ns1:sayHello" name="parameters" />
    </wsdl:message>

4. <portType/>.net

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

        <!-- 
        portType:用来指定服务器端的SEI(接口)
        operation:表示操做/行为,即SEI中定义的方法
        input:方法sayHello的输入
        output:方法sayHello的输出
        输入输出引用的是上面message的定义
     -->
    <wsdl:portType name="ISayHello">
        <wsdl:operation name="sayHello">
            <wsdl:input message="ns1:sayHello" name="sayHello" />
            <wsdl:output message="ns1:sayHelloResponse" name="sayHelloResponse" />
        </wsdl:operation>
    </wsdl:portType>

5. <binding/>orm

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

    <!-- 
        binding:用来指定SEI的实现类
        type属性:引用<portType>定义
        <soap:binding style="document">:表示传输的一个document (xml)
        <input><output>与上节说的相同
        <soap:body use="literal" />:表示body传输采用文本即xml格式的文本
     -->
    <wsdl:binding name="SayHelloImplServiceSoapBinding" type="ns1:ISayHello">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="sayHello">
            <soap:operation soapAction="" style="document" />
            <wsdl:input name="sayHello">
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output name="sayHelloResponse">
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

6. <service>

    <!-- 
        service:相同于webservice容器,也可理解为一个工厂
        name:用于指定客户端的容器类/工厂类,客户端代码今后类开始
        port:用来指定服务器端的一个入口(对应SEI的实现类)
        port binding:引用上面定义的
        port name:容器经过这个方法得到实现类
        address:客户端真正用于请求的地址
        
        回想咱们的demo:
        SayHelloImplService factory = new SayHelloImplService();
        SayHelloImpl sayHelloImpl = factory.getSayHelloImplPort();
     -->
    <wsdl:service name="SayHelloImplService">
        <wsdl:port binding="tns:SayHelloImplServiceSoapBinding"
            name="SayHelloImplPort">
            <soap:address location="http://132.122.239.74:8089/ws/sayhello" />
        </wsdl:port>
    </wsdl:service>

7. 总结

 

转自:https://blog.csdn.net/posonrick/article/details/45580355?utm_source=blogxgwz1