webservice wsdl語法基礎


XML-WSDL基礎知識

  1. WSDL

1.1. WSDL 簡介

1.1.1.    概述

WSDL 指網絡服務描述語言 (Web Services Description Language)

WSDL 是基於 XML 的用於描述 Web Services 以及如何訪問 Web Services 的語言。

做為通訊協議,在web通訊中消息的格式被標准化的。WSDL為描述網絡服務定義XML語法使交互的端點之間擁有信息交互的能力。WSDL服務定義為分布式系統提供了證據並且擔任自動參與在應用通訊中處理的方法。

WSDL文檔定義服務作為絡交互的端點或者ports的集合。在WSDL中,抽象的定義了端點和從網絡部署或數據格式綁定分離的消息。允許重用抽象定義:messages(抽象的描述交互的數據);port typesoperations的集合)。對一個特定port type指定明確的協議和數據格式組成了一個可重用的binding。通過將一個網絡地址關聯到可重用的banging,定義了一個portport的集合定義了一個服務。因此,WSDL通過以下元素定義網絡服務:

²  Type-包含使用類型系統(例如XSD)創建的數據類型的定義的容器。

²  Message-一個抽象的、典型的關於用於交互的數據定義。

²  Operation-一個服務支持的行為(方法)的抽象描述。

²  PortType-被一個或多個端點支持的一系列操作的抽象。

²  Binding-一個明確的協議和為特定porttype指定的數據格式。

²  Port-一個由網絡地址和一個綁定組合的單一的端點

²  Service-相關端點的集合。

WSDL沒有采用新的類型定義語言。WSDL發現需要一個富類型系統來描述消息格式,並已XML Schema(XSD)作為其權威的類型系統。通過擴展,WSDL允許使用其他類型定義語言來描述消息。

另外,WSDL定義了一個通過的binding機制,被用於連接指定的協議或數據格式或抽象消息/操作/端點的結構,允許被重用。

      除了核心服務定義框架,本文檔介紹以下的協議和消息格式作為binding的擴展。

²  SOAP 1.1

²  HTTP GET / POST

²  MIME

1.1.2.    一個WSDL例子

<?xml version="1.0"?>

<definitions name="StockQuote"

 

targetNamespace="http://example.com/stockquote.wsdl"

          xmlns:tns="http://example.com/stockquote.wsdl"

          xmlns:xsd1="http://example.com/stockquote.xsd"

          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

          xmlns="http://schemas.xmlsoap.org/wsdl/">

 

    <types>

       <schema targetNamespace="http://example.com/stockquote.xsd"

              xmlns="http://www.w3.org/2000/10/XMLSchema">

           <element name="TradePriceRequest">

              <complexType>

                  <all>

                      <element name="tickerSymbol" type="string"/>

                  </all>

              </complexType>

           </element>

           <element name="TradePrice">

              <complexType>

                  <all>

                      <element name="price" type="float"/>

                  </all>

              </complexType>

           </element>

       </schema>

    </types>

 

    <message name="GetLastTradePriceInput">

        <part name="body" element="xsd1:TradePriceRequest"/>

    </message>

 

    <message name="GetLastTradePriceOutput">

        <part name="body" element="xsd1:TradePrice"/>

    </message>

 

    <portType name="StockQuotePortType">

        <operation name="GetLastTradePrice">

           <input message="tns:GetLastTradePriceInput"/>

           <output message="tns:GetLastTradePriceOutput"/>

        </operation>

    </portType>

 

    <binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">

        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

        <operation name="GetLastTradePrice">

           <soap:operation soapAction="http://example.com/GetLastTradePrice"/>

           <input>

               <soap:body use="literal"/>

           </input>

           <output>

               <soap:body use="literal"/>

           </output>

        </operation>

    </binding>

 

    <service name="StockQuoteService">

        <documentation>My first service</documentation>

        <port name="StockQuotePort" binding="tns:StockQuoteBinding">

           <soap:address location="http://example.com/stockquote"/>

        </port>

    </service>

 

</definitions>

服務支持一個唯一的操作GetLastTradePrice,該操作通過SOAP1.1協議覆蓋HTTP進行部署。請求參數為一個string類型的tickerSymbol,返回一個float的price。

該例子使用固定的XML格式替代SOAP編碼。

1.1.3.    符號的約定

  1. 關鍵字

a)     "MUST","REQUIRED", "SHALL"表示元素必需定義

b)     "MUST NOT",  "SHALL NOT"表示絕對禁止的元素。

c)     "SHOULD","RECOMMENDED"

d)     "MAY", "OPTIONAL"表示可選的。

e)     "SHOULD NOT","NOT RECOMMENDED"

f)       

  1. 文檔使用的命名空間前綴:

prefix

namespace URI

definition

wsdl

http://schemas.xmlsoap.org/wsdl/

WSDL namespace for WSDL framework.

soap

http://schemas.xmlsoap.org/wsdl/soap/

WSDL namespace for WSDL SOAP binding.

http

http://schemas.xmlsoap.org/wsdl/http/

WSDL namespace for WSDL HTTP GET & POST binding.

mime

http://schemas.xmlsoap.org/wsdl/mime/

WSDL namespace for WSDL MIME binding.

soapenc

http://schemas.xmlsoap.org/soap/encoding/

Encoding namespace as defined by SOAP 1.1

soapenv

http://schemas.xmlsoap.org/soap/envelope/

Envelope namespace as defined by SOAP 1.1

xsi

http://www.w3.org/2000/10/XMLSchema-instance

Instance namespace as defined by XSD

xsd

http://www.w3.org/2000/10/XMLSchema

Schema namespace as defined by XSD .

tns

(various)

The “this namespace” (tns) prefix is used as a convention to refer to the current document.

(other)

(various)

All other namespace prefixes are samples only. In particular, URIs starting with “http://example.com” represent some application-dependent or context-dependent URI [4].

3. WSDL使用非正式的語句描述XML語法

      語句的產生作為XML的實例,但是值指示通過數據類型代替。

      通配符:”?”-0個或1個;”*”-0個或多個;”+”-1個或多個,至少一個

      元素后加"…" (例如<element…/> or <element…>)表明上下文不相干的元素或屬性被忽略

1.2. WSDL 文檔結構

1.2.1.    文檔結構

WSDL 文檔是利用這些主要的元素來描述某個 web service 的:

元素

定義

<types>

web service 使用的描述數據交互的數據類型,為了最大程度的平台中立性,WSDL 使用 XML Schema 語法來定義數據類型

<message>

web service 用於傳輸的數據的抽象。消息由邏輯部件組成,每個邏輯部件關聯已定義的類型;每個消息均由一個或多個部件組成。可以把這些部件比作傳統編程語言中一個函數調用的參數。

<portType>

描述一個 web service、可被執行的操作,以及相關的消息;可以把 <portType> 元素比作傳統編程語言中的一個函數庫(或一個模塊、或一個類)。

<binding>

web service 使用的通信協議和數據格式,為每個port定義消息格式和協議細節。

<port>

指定綁定的地址,定義一個唯一的通訊端點。

<service>

聚集有關port的集合

一個 WSDL 文檔的主要結構是類似這樣的:

1.2.2.    文檔命名和鏈接

WSDL文件可以被復制一個可選的name屬性,targetNamespace屬性指定一個URL類型。

通過使用import語句,WSDL允許在文檔本地關聯一個namesapce。

<definitions .... >

    <import namespace="uri" location="uri"/> *

</definitions>

1.2.3.    編寫風格

通過import元素可以使一個service的不同元素分別定義至獨立的文檔,在需要的時候被導入。最大程度的重用服務的定義,以下示例顯示了使用編寫風格定義上述示例

http://example.com/stockquote/stockquote.xsd

<?xml version="1.0"?>

<schema targetNamespace="http://example.com/stockquote/schemas"

       xmlns="http://www.w3.org/2000/10/XMLSchema">

      

    <element name="TradePriceRequest">

        <complexType>

            <all>

                <element name="tickerSymbol" type="string"/>

            </all>

        </complexType>

    </element>

    <element name="TradePrice">

        <complexType>

            <all>

                <element name="price" type="float"/>

            </all>

        </complexType>

    </element>

</schema>

http://example.com/stockquote/stockquote.wsdl

<?xml version="1.0"?>

<definitions name="StockQuote"

 

targetNamespace="http://example.com/stockquote/definitions"

          xmlns:tns="http://example.com/stockquote/definitions"

          xmlns:xsd1="http://example.com/stockquote/schemas"

          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

          xmlns="http://schemas.xmlsoap.org/wsdl/">

 

   <import namespace="http://example.com/stockquote/schemas"

           location="http://example.com/stockquote/stockquote.xsd"/>

 

    <message name="GetLastTradePriceInput">

        <part name="body" element="xsd1:TradePriceRequest"/>

    </message>

 

    <message name="GetLastTradePriceOutput">

        <part name="body" element="xsd1:TradePrice"/>

    </message>

 

    <portType name="StockQuotePortType">

        <operation name="GetLastTradePrice">

           <input message="tns:GetLastTradePriceInput"/>

           <output message="tns:GetLastTradePriceOutput"/>

        </operation>

    </portType>

</definitions>

http://example.com/stockquote/stockquoteservice.wsdl

<?xml version="1.0"?>

<definitions name="StockQuote"

 

targetNamespace="http://example.com/stockquote/service"

          xmlns:tns="http://example.com/stockquote/service"

          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

          xmlns:defs="http://example.com/stockquote/definitions"

          xmlns="http://schemas.xmlsoap.org/wsdl/">

 

   <import namespace="http://example.com/stockquote/definitions"

           location="http://example.com/stockquote/stockquote.wsdl"/>

 

    <binding name="StockQuoteSoapBinding" type="defs:StockQuotePortType">

        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

        <operation name="GetLastTradePrice">

           <soap:operation soapAction="http://example.com/GetLastTradePrice"/>

           <input>

               <soap:body use="literal"/>

           </input>

           <output>

               <soap:body use="literal"/>

           </output>

        </operation>

    </binding>

 

    <service name="StockQuoteService">

        <documentation>My first service</documentation>

        <port name="StockQuotePort" binding="tns:StockQuoteBinding">

           <soap:address location="http://example.com/stockquote"/>

        </port>

    </service>

</definitions>

      該示例分為三個文檔定義:數據類型定義,概要定義,服務綁定。

1.2.4.    語言擴展和綁定

在WSDL中,綁定指定處理關聯協或者對於概要實體(message,operation或portType)的數據格式信息。擴展點用於為一個特殊的協議和消息格式指定綁定信息,但是並不現實使用。擴展元素MUST使用一個不同於WSDL的XML命名空間。

location

Possible usage

definitions

為整個WSDL介紹額外的信息或者定義

definitions/types

指定message在type系統中的格式

definitions/service

為服務介紹額外的信息和定義

definitions/service/port

為port指定地址

definitions/binding

在port type范圍內,提供協議指定應用於操作的信息

definitions/binding/operation

提供指定應用與input和output消息的信息

definitions/binding/operation/input

提供關於概要信息部分如何映射到明確協議和數據格式的明細。

為輸入消息提供額外的協議指定信息

definitions/binding/operation/output

提供關於概要信息部分如何映射到明確協議和數據格式的明細

為輸出消息提供額外的協議指定信息

definitions/binding/operation/fault

提供關於概要信息部分如何映射到明確協議和數據格式的明細

為錯誤信息提供額外的協議指定信息

1.2.5.     文檔化

WSDL使用可選的wsdl:document元素作為用於可讀性文檔化的一個容器。該元素允許在任何WSDL語言元素中使用。

 

1.2.6.    WSDL 實例

這是某個 WSDL 文檔的簡化的片段:

<wsdl:definitions name="nmtoken"? targetNamespace="uri"?>

    <import namespace="uri" location="uri"/>*

    <wsdl:documentation .... /> ?

    <wsdl:types> ?

        <wsdl:documentation .... />?

        <xsd:schema .... />*

        <-- extensibility element --> *

    </wsdl:types>

 

    <wsdl:message name="nmtoken"> *

        <wsdl:documentation .... />?

        <part name="nmtoken" element="qname"? type="qname"?/> *

    </wsdl:message>

 

    <wsdl:portType name="nmtoken">*

        <wsdl:documentation .... />?

        <wsdl:operation name="nmtoken">*

           <wsdl:documentation .... /> ?

           <wsdl:input name="nmtoken"? message="qname">?

               <wsdl:documentation .... /> ?

           </wsdl:input>

           <wsdl:output name="nmtoken"? message="qname">?

               <wsdl:documentation .... /> ?

           </wsdl:output>

           <wsdl:fault name="nmtoken" message="qname"> *

               <wsdl:documentation .... /> ?

           </wsdl:fault>

        </wsdl:operation>

    </wsdl:portType>

 

    <wsdl:binding name="nmtoken" type="qname">*

        <wsdl:documentation .... />?

        <-- extensibility element --> *

        <wsdl:operation name="nmtoken">*

           <wsdl:documentation .... /> ?

           <-- extensibility element --> *

           <wsdl:input> ?

               <wsdl:documentation .... /> ?

               <-- extensibility element -->

           </wsdl:input>

           <wsdl:output> ?

               <wsdl:documentation .... /> ?

               <-- extensibility element --> *

           </wsdl:output>

           <wsdl:fault name="nmtoken"> *

               <wsdl:documentation .... /> ?

               <-- extensibility element --> *

           </wsdl:fault>

        </wsdl:operation>

    </wsdl:binding>

 

    <wsdl:service name="nmtoken"> *

        <wsdl:documentation .... />?

        <wsdl:port name="nmtoken" binding="qname"> *

           <wsdl:documentation .... /> ?

           <-- extensibility element -->

        </wsdl:port>

        <-- extensibility element -->

    </wsdl:service>

 

    <-- extensibility element --> *

 

</wsdl:definitions>

 

1.3. WSDL Types

Types元素封裝了關於數據交互信息的數據類型定義。

為了實現最大程度的協同工作能力和平台無關,WSDL比較喜歡使用XSD作為權威的類型系統,並且作為固有的類型系統。

<definitions .... >
    <types>
        <xsd:schema .... />*
    </types>
</definitions>

XSD類型系統能夠用於定義在消息中定義類型。如果對相同的消息指定多個綁定,或者只有一個綁定但是綁定類型對應的類型系統並沒有廣泛使用,推薦遵循以下內容使用XSD:

²  使用element形式(沒有屬性)

²  不包含對於編碼來說獨特的屬性或元素(例如:對於與消息的概要內容來說什么也沒有做)。一些例子有:saop:root,soap:encodingStyle,xmi:id,xmi:name

²  數組類型需要擴展SOAP1.1 encoding 結構(http://schemas.xmlsoap.org/soap/encoding/)的數組類型的定義,為數組類型使用名字ArraryofXXX(XXX標示數組元素的基本類型)。通過使用soapenc:arrayType屬性的默認值指定元素的類型和元素的規模。當前XSD不支持包含QName值的屬性的默認值。

²  使用xsd:anyTYpe標示字段/參數可是是任何類型。

 

期望只有一種類型系統能夠描述所有的類型是不現實的,WSDL允許類型系統憑借擴展的元素增加。擴展元素在types元素下定義產生一個類型定義的容器元素。

<definitions .... >
    <types>
        <-- type-system extensibility element --> *
    </types>
</definitions>

1.4. WSDL Messages

Messages由一個活多個邏輯部分組成,每個邏輯部分使用message-typing屬性關聯類型系統對應的一個類型。一組message-typing屬性是可擴展的。WSDL使用XSD定義了數個message-typing屬性:

²  element:使用一個QName指定XSD元素

²  type:使用一個QName指定一個XSD的簡單類型或復制類型。

其他message-type屬性只要使用不同於WSDL的namespace定義。綁定擴展的屬性也使用message-typing屬性。

定義message的語法如下:

<definitions .... >
    <message name="nmtoken"> *
        <part name="nmtoken" element="qname"? type="qname"?/> *
    </message>
</definitions>

用黑標標出部分為message-type對應的屬性。

message元素的name屬性指定了一個唯一的message名字。

part元素的name屬性提供了在message中的一個唯一的part名字。

1.4.1.    Message Parts

Parts是描述Message邏輯抽象內容的一種機制。一個binding可能指定part的名字為了詳述關於part的綁定信息。例如,如果使用RPC(遠程過程調用)定義一個message,part可能代表了信息的一個參數。無論如何,為了確定part的真實意義必須檢查binding。

如果message擁有多個邏輯單元,那么就有多個part元素被使用。例如,下面的message有一個Purchase Order和一個Invoice組成:

<definitions .... >

    <types>

        <schema .... >

           <element name="PO" type="tns:POType"/>

           <complexType name="POType">

               <all>

                   <element name="id" type="string/>

                   <element name="name" type="string"/>

                   <element name="items">

                       <complexType>

                           <all>

                               <element name="item" type="tns:Item" minOccurs="0" maxOccurs="unbounded"/>

                           </all>

                       </complexType>

                   </element>

              </all>

           </complexType>

 

           <complexType name="Item">

               <all>

                   <element name="quantity" type="int"/>

                   <element name="product" type="string"/>

               </all>

           </complexType>

           <element name="Invoice" type="tns:InvoiceType"/>

           <complexType name="InvoiceType">

               <all>

                   <element name="id" type="string"/>

               </all>

           </complexType>

        </schema>

    </types>

 

    <message name="PO">

        <part name="po" element="tns:PO"/>

        <part name="invoice" element="tns:Invoice"/>

    </message>

</definitions>

無論如何,如果消息的內容十分復雜的,那么使用指定的由type system直接定義的message綜合結構。在這種情況下,只有一個part被指定。在以下的例子中,body及時purchase order,也是一組invoice

<definitions .... >
    <types>
        <schema .... >
           <complexType name="POType">
               <all>
                   <element name="id" type="string/>
                   <element name="name" type="string"/>
                   <element name="items">
                       <complexType>
                           <all>
                               <element name="item" type="tns:Item" minOccurs="0" maxOccurs="unbounded"/>
                           </all>                          
                       </complexType>
                   </element>
               </all>
           </complexType>
 
           <complexType name="Item">
               <all>
                   <element name="quantity" type="int"/>
                   <element name="product" type="string"/>
               </all>
           </complexType>
           <complexType name="InvoiceType">
               <all>
                   <element name="id" type="string"/>
               </all>
           </complexType>
 
           <complexType name="Composite">
               <choice>
                   <element name="PO" minOccurs="1" maxOccurs="1" type="tns:POType"/>
                   <element name="Invoice" minOccurs="0" maxOccurs="unbounded" type="tns:InvoiceType"/>
               </choice>
           </complexType>
        </schema>
    </types>
 
    <message name="PO">
        <part name="composite" type="tns:Composite"/>
    </message>
</definitions>

1.4.2.    Abstract vs. Concrete Messages

Message定義一般被考慮是一個message內容抽象定義。一個message綁定描述了抽象內容如何映射到明確的格式,盡管如此,在一些例子中,抽象定義對於一個或多個綁定來說非常接近明其明確的代表,因此binding可能提供較少的或不提供映射信息。無論如何,對於那個相同message定義的另外的綁定可能需要擴展映射信息,理由是,直到檢查綁定后才能確定當前的message有多抽象。

1.5. WSDL Port Types

<portType> 元素是最重要的 WSDL 元素。它可描述一個 web service、可被執行的操作,以及相關的消息。端口定義了指向某個 web service 的連接點。可以把該元素比作傳統編程語言中的一個函數庫(或一個模塊、或一個類),而把每個操作比作傳統編程語言中的一個函數。

      Port 類型是一個包含抽象operation和抽象messsage的集合。

<wsdl:definitions .... >
<wsdl:portType name="nmtoken">
   <!—通過name屬性命名operation-->
        <wsdl:operation name="nmtoken" .... /> *
    </wsdl:portType>
</wsdl:definitions>

    Port type的name屬性提供了在WSDL文件中,對於所有port type來說唯一的名字。

1.5.1.    操作類型

請求-響應是最普通的操作類型,不過 WSDL 定義了四種類型:

類型

定義

One-way

此操作可接受消息,但不會返回響應。

Request-response

此操作可接受一個請求並會發送一個相關的消息

Solicit-response

此操作可發送一個請求,並會接受一個相關的響應。

Notification

此操作可發送一條消息,但不會等待響應。

WSDL指定了這些原始的操作,然而request/response或者solicit/response在理論上可以使用兩個one-way的message模仿,因為以下原因,模型原始的操作是很有用的:

²  非常平凡的

²  Sequence能夠被關聯,不需要引入更多復雜的流信息。

²  對於響應同步請求的返回,很多節點只需要接受message

²  當渴望一個flow定義,能夠簡單的從這些原始操作得到

盡管 request/response 或 solicit/response 在WSDL文件中被邏輯關聯,一個給定的binding描述了明確的關聯信息.例如,request和response messages 可以再一個或兩個實際通訊的網絡中進行交互。

盡管基本的WSDL結構支持4中傳播原型的binding。WSDL僅僅為One-way和Request-response原型定義了binding。WSDL binding擴展允許使用Solicit-response 或 Notification。

Message屬性是QName類型

1.5.2.    One-way 操作

One-Way操作的語法:

<wsdl:definitions .... > <wsdl:portType .... > *

        <wsdl:operation name="nmtoken">

           <wsdl:input name="nmtoken"? message="qname"/>

        </wsdl:operation>

    </wsdl:portType >

</wsdl:definitions>

      Input元素詳述了one-way操作的抽象的message格式。

1.5.3.    Request-response 操作

request-response操作的語法:

<wsdl:definitions .... >

    <wsdl:portType .... > *

        <wsdl:operation name="nmtoken" parameterOrder="nmtokens">

           <wsdl:input name="nmtoken"? message="qname"/>

           <wsdl:output name="nmtoken"? message="qname"/>

           <wsdl:fault name="nmtoken" message="qname"/>*

        </wsdl:operation>

    </wsdl:portType >

</wsdl:definitions>

Input和output元素分別表示request和response的抽象的消息格式。可選項fault元素表示作為操作結果輸出的錯誤信息的抽象消息格式。

request-response操作是一個抽象的概念,一個特殊的binding必須考慮如何在一個通訊(例如,一個HTTP 請求/響應)或兩個獨立的通訊(例如,兩個HTTP請求)中真正的發送消息。

1.5.4.    Solicit-response 操作

solicit-response操作的語法:

<wsdl:definitions .... >

    <wsdl:portType .... > *

        <wsdl:operation name="nmtoken" parameterOrder="nmtokens">

           <wsdl:output name="nmtoken"? message="qname"/>

           <wsdl:input name="nmtoken"? message="qname"/>

           <wsdl:fault name="nmtoken" message="qname"/>*

        </wsdl:operation>

    </wsdl:portType >

</wsdl:definitions>

Output和input元素分別標示一個請求和其響應的抽象的message格式。可選項fault元素表示作為操作結果輸出的錯誤信息的抽象消息格式。

Note:solicit-response是一個抽象的概念,一個特定的binding必須考考慮如何在一個通訊(例如,一個HTTP 請求/響應)或兩個獨立的通訊(例如,兩個HTTP請求)中真正的發送消息。

1.5.5.    Notification 操作

Notification操作的語法:

<wsdl:definitions .... >

    <wsdl:portType .... > *

        <wsdl:operation name="nmtoken">

           <wsdl:output name="nmtoken"? message="qname"/>

        </wsdl:operation>

    </wsdl:portType >

</wsdl:definitions>

    Output參數指定了notification操作的抽象的message格式。

1.5.6.    Operation中name元素

Input和output元素的name屬性為port Type中的input和output元素提供了一個唯一的名字。

 

In order to avoid having to name each input and output element within an operation, WSDL provides some default values based on the operation name. If the name attribute is not specified on a one-way or notification message, it defaults to the name of the operation. If the name attribute is not specified on the input or output messages of a request-response or solicit-response operation, the name defaults to the name of the operation with "Request"/"Solicit" or "Response" appended, respectively.

Each fault element must be named to allow a binding to specify the concrete format of the fault message. The name of the fault element is unique within the set of faults defined for the operation.

2.4.6 Parameter Order within an Operation

Operations do not specify whether they are to be used with RPC-like bindings or not. However, when using an operation with an RPC-binding, it is useful to be able to capture the original RPC function signature. For this reason, a request-response or solicit-response operation MAY specify a list of parameter names via the parameterOrder attribute (of type nmtokens). The value of the attribute is a list of message part names separated by a single space. The value of the parameterOrder attribute MUST follow the following rules:

  • The part name order reflects the order of the parameters in the RPC signature
  • The return value part is not present in the list
  • If a part name appears in both the input and output message, it is an in/out parameter
  • If a part name appears in only the input message, it is an in parameter
  • If a part name appears in only the output message, it is an out parameter

Note that this information serves as a "hint" and may safely be ignored by those not concerned with RPC signatures. Also, it is not required to be present, even if the operation is to be used with an RPC-like binding.

1.6.  WSDL 端口

WSDL 端口可描述由某個 web service 提供的界面(合法操作)。

1.6.1.    WSDL 端口

1.6.2.    One-Way 操作

一個 one-way 操作的例子:

<message name="newTermValues">

   <part name="term" type="xs:string"/>

   <part name="value" type="xs:string"/>

</message>

 

<portType name="glossaryTerms">

   <operation name="setTerm">

      <input name="newTerm" message="newTermValues"/>

   </operation>

</portType >

在這個例子中,端口 "glossaryTerms" 定義了一個名為 "setTerm" 的 one-way 操作。

這個 "setTerm" 操作可接受新術語表項目消息的輸入,這些消息使用一條名為 "newTermValues" 的消息,此消息帶有輸入參數 "term" 和 "value"。不過,沒有為這個操作定義任何輸出。

1.6.3.    Request-Response 操作

一個 request-response 操作的例子:

<message name="getTermRequest">

   <part name="term" type="xs:string"/>

</message>

 

<message name="getTermResponse">

   <part name="value" type="xs:string"/>

</message>

 

<portType name="glossaryTerms">

  <operation name="getTerm">

    <input message="getTermRequest"/>

    <output message="getTermResponse"/>

  </operation>

</portType>

在這個例子中,端口 "glossaryTerms" 定義了一個名為 "getTerm" 的 request-response 操作。

"getTerm" 操作會請求一個名為 "getTermRequest" 的輸入消息,此消息帶有一個名為 "term" 的參數,並將返回一個名為 "getTermResponse" 的輸出消息,此消息帶有一個名為 "value" 的參數。

1.7. WSDL 綁定

WSDL 綁定可為 web service 定義消息格式和協議細節。.

WSDL提供了一個模型和描述Web Services的XML格式。WSDL SOAP1.1綁定描述了對於SOAP1.1協議的綁定的擴展。該綁定被規定為方便的將使用SOAP1.1協議描述的實現從WSDL1.1遷移到WSDL2.0。並且綁定允許使用者繼續使用SOAP1.1協議。

1.7.1.    符號約定

描述了使用一系列命名空間前綴貫穿全文。選擇任何命名空間前綴是隨意的並且沒有特別重要的語義。

前綴

命名空間

wsdl

"http://www.w3.org/ns/wsdl"

wsoap

"http://www.w3.org/ns/wsdl/soap"

whttp

"http://www.w3.org/ns/wsdl/http"

xs

"http://www.w3.org/2001/XMLSchema"

1.7.2.    SOAP1.1

通過WSDL輔助的SOAP綁定擴展,SOAP1.1綁定能夠使Web Service應用使用SOAP1.1.這類綁定有以下的支持:

      消息裝換模型:支持兩種消息消息轉換模型:In-Out和In-Only

      SOAP模塊:支持SOAP模塊並且允許用戶使用SOAP Module組件指示SOAP模塊。“SOAP Module”(也被認為是SOAP擴展),指定語法和一個或多個SOAP頭的語義。要求在SOAP1.1綁定中指定一個SOAP Module。

      SOAP1.1 HTTP綁定:

  • SOAP 1.1 HTTP Binding - supports the SOAP 1.1 HTTP binding defined in Section 6, SOAP 1.1 specification [SOAP11]. This is indicated by assigning the URI "http://www.w3.org/2006/01/soap11/bindings/HTTP/" to the {soap underlying protocol} property.

The value of the {soap action} property, if present, identifies the value of the SOAP 1.1 SOAPAction HTTP request header field, Section 6.1.1, SOAP 1.1 specification [SOAP11].

The values of {http location} properties are ignored for SOAP 1.1 HTTP binding.

Note:

If the Interface Operation component's {message exchange pattern} property has the value "http://www.w3.org/ns/wsdl/in-only" and the Binding component's {soap underlying protocol} property has the value"http://www.w3.org/2006/01/soap11/bindings/HTTP/", then the HTTP response is undefined. For specific guidance on what the HTTP response ought to be, implementers are referred to the Basic Profile [BP10] and/or the latest version of this specification(s).

  • Other SOAP 1.1 Underlying Protocols - supports other SOAP 1.1 underlying protocols. Other values can be used for the {soap underlying protocol} property in conjunction with the SOAP 1.1 binding provided that the semantics of such protocols are consistent with this binding.

The values of {soap mep default}, {soap mep} and {soap fault subcodes} properties are ignored for SOAP 1.1 binding.

 

1.7.3.    綁定到 SOAP

一個 請求 - 響應 操作的例子:

<message name="getTermRequest">

   <part name="term" type="xs:string" />

</message>

 

<message name="getTermResponse">

   <part name="value" type="xs:string" />

</message>

 

<portType name="glossaryTerms">

  <operation name="getTerm">

      <input message="getTermRequest" />

      <output message="getTermResponse" />

  </operation>

</portType>

 

<binding type="glossaryTerms" name="b1">

<soap:binding style="document"

transport="http://schemas.xmlsoap.org/soap/http" />

  <operation>

    <soap:operation

     soapAction="http://example.com/getTerm" />

    <input>

      <soap:body use="literal" />

    </input>

    <output>

      <soap:body use="literal" />

    </output>

  </operation>

</binding>

binding 元素有兩個屬性 - name 屬性和 type 屬性。

²  name 屬性定義 binding 的名稱,

²  type 屬性指向用於 binding 的端口,在這個例子中是 "glossaryTerms" 端口。

soap:binding 元素有兩個屬性

²  style 屬性: 可取值 "rpc" 或 "document"。在這個例子中我們使用 document。

²  transport 屬性: 定義了要使用的 SOAP 協議。在這個例子中我們使用 HTTP。

operation 元素定義了每個端口提供的操作符。對於每個操作,相應的 SOAP 行為都需要被定義。同時您必須如何對輸入和輸出進行編碼。在這個例子中我們使用了 "literal"。

1.8. WSDL 和 UDDI

UDDI 是一種目錄服務,企業可以使用它對 Web services 進行注冊和搜索。

UDDI,英文為 "Universal Description, Discovery and Integration",可譯為通用描述、發現與集成服務

1.8.1.    什么是 UDDI?

UDDI 是一個獨立於平台的框架,用於通過使用 Internet 來描述服務,發現企業,並對企業服務進行集成。

²  UDDI 指的是通用描述、發現與集成服務

²  UDDI 是一種用於存儲有關 web services 的信息的目錄。

²  UDDI 是一種由 WSDL 描述的 web services 界面的目錄。

²  UDDI 經由 SOAP 進行通信

²  UDDI 被構建入了微軟的 .NET 平台

1.8.2.    UDDI 基於什么?

UDDI 使用 W3C 和 IETF(Internet Engineering Task Force) 的因特網標准,比如 XML、HTTP 和 DNS 協議。

UDDI 使用 WSDL 來描述到達 web services 的界面

此外,通過采用 SOAP,還可以實現跨平台的編程特性,大家知道,SOAP 是 XML 的協議通信規范,可在 W3C 的網站找到相關的信息。

1.8.3.    UDDI 的好處

任何規模的行業或企業都能得益於 UDDI。

在 UDDI 之前,還不存在一種 Internet 標准,可以供企業為它們的企業和伙伴提供有關其產品和服務的信息。也不存在一種方法,來集成到彼此的系統和進程中。

UDDI 規范幫助我們解決的問題:

²  使得在成百萬當前在線的企業中發現正確的企業成為可能

²  定義一旦首選的企業被發現后如何啟動商業

²  擴展新客戶並增加對目前客戶的訪問

²  擴展銷售並延伸市場范圍

²  滿足用戶驅動的需要,為在全球 Internet 經濟中快速合作的促進來清除障礙

1.8.4.    UDDI 如何被使用

假如行業發布了一個用於航班比率檢測和預訂的 UDDI 標准,航空公司就可以把它們的服務注冊到一個 UDDI 目錄中。然后旅行社就能夠搜索這個 UDDI 目錄以找到航空公司預訂界面。當此界面被找到后,旅行社就能夠立即與此服務進行通信,這樣由於它使用了一套定義良好的預訂界面。

1.8.5.    誰在支持 UDDI?

UDDI 是一個跨行業的研究項目,由所有主要的平台和軟件提供商驅動,比如:Dell, Fujitsu, HP, Hitachi, IBM, Intel, Microsoft, Oracle, SAP, 以及 Sun, 它既是一個市場經營者的團體,也是一個電子商務的領導者。

已有數百家公司參與了這個 UDDI 團體。

1.9. 完整的 WSDL 語法

描述於 W3C 工作草案的完整 WSDL 1.2 語法已列在下面:

<wsdl:definitions name="nmtoken"? targetNamespace="uri">
 
    <import namespace="uri" location="uri"/> *
    
    <wsdl:documentation .... /> ?
 
    <wsdl:types> ?
        <wsdl:documentation .... /> ?
        <xsd:schema .... /> *
    </wsdl:types>
 
    <wsdl:message name="ncname"> *
        <wsdl:documentation .... /> ?
        <part name="ncname" element="qname"? type="qname"?/> *
    </wsdl:message>
 
    <wsdl:portType name="ncname"> *
        <wsdl:documentation .... /> ?
        <wsdl:operation name="ncname"> *
            <wsdl:documentation .... /> ?
            <wsdl:input message="qname"> ?
                <wsdl:documentation .... /> ?
            </wsdl:input>
            <wsdl:output message="qname"> ?
                <wsdl:documentation .... /> ?
            </wsdl:output>
            <wsdl:fault name="ncname" message="qname"> *
                <wsdl:documentation .... /> ?
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:portType>
 
    <wsdl:serviceType name="ncname"> *
        <wsdl:portType name="qname"/> +
    </wsdl:serviceType>
 
    <wsdl:binding name="ncname" type="qname"> *
        <wsdl:documentation .... /> ?
        <-- binding details --> *
        <wsdl:operation name="ncname"> *
            <wsdl:documentation .... /> ?
            <-- binding details --> *
            <wsdl:input> ?
                <wsdl:documentation .... /> ?
                <-- binding details -->
            </wsdl:input>
            <wsdl:output> ?
                <wsdl:documentation .... /> ?
                <-- binding details --> *
            </wsdl:output>
            <wsdl:fault name="ncname"> *
                <wsdl:documentation .... /> ?
                <-- binding details --> *
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
 
    <wsdl:service name="ncname" serviceType="qname"> *
        <wsdl:documentation .... /> ?
        <wsdl:port name="ncname" binding="qname"> *
            <wsdl:documentation .... /> ?
            <-- address details -->
        </wsdl:port>
    </wsdl:service>
 
</wsdl:definitions>

1.10.    總結

1.10.1.   WSDL 概要

本教程已為您講解了如何創建可描述 web 服務的 WSDL 文檔。它也規定了服務的位置和服務所提供的操作(或方法)。

您已經學習到如何為 web 服務定義消息格式和協議細節。

您也學習了可通過 UDDI 來注冊和搜索 web 服務。

1.10.2.   您已經學習了 WSDL,下一步呢?

下一步應該學習 SOAP 和 Web Services。

SOAP 是一種基於 XML 的簡易協議,允許應用程序通過 HTTP 來交換信息。

或者更簡單地講,SOAP 是用於訪問 web 服務的協議。

如果您希望學習更多有關 SOAP 的知識,請訪問我們的 SOAP 教程

Web services 可把您的應用程序轉換為 web 應用程序。通過使用 XML,可以在應用程序間傳送消息。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM