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

相關文章
相關標籤/搜索