Latest web development tutorials

WSDL 文檔

WSDL 文檔僅僅是一個簡單的XML 文檔。

它包含一系列描述某個web service 的定義。


WSDL 文檔結構

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

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

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

<definitions>

<types>
data type definitions........
</types>

<message>
definition of the data being communicated....
</message>

<portType>
set of operations......
</portType>

<binding>
protocol and data format specification....
</binding>

</definitions>

WSDL 文檔可包含其它的元素,比如extension 元素,以及一個service 元素,此元素可把若干個web services 的定義組合在一個單一的WSDL 文檔中。


WSDL 端口

<portType>元素是最重要的WSDL元素。

它可描述一個web service、可被執行的操作,以及相關的消息。

可以把<portType> 元素比作傳統編程語言中的一個函數庫(或一個模塊、或一個類)。


WSDL 消息

<message>元素定義一個操作的數據元素。

每個消息均由一個或多個部件組成。 可以把這些部件比作傳統編程語言中一個函數調用的參數。


WSDL types

<types>元素定義web service使用的數據類型。

為了最大程度的平台中立性,WSDL 使用XML Schema 語法來定義數據類型。


WSDL Bindings

<binding>元素為每個端口定義消息格式和協議細節。


WSDL 實例

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

<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>

在這個例子中, <portType>元素把"glossaryTerms"定義為某個端口的名稱,把"getTerm"定義為某個操作的名稱。

操作"getTerm"擁有一個名為"getTermRequest"的輸入消息 ,以及一個名為"getTermResponse"的輸出消息

<message>元素可定義每個消息的部件 ,以及相關聯的數據類型。

對比傳統的編程,glossaryTerms 是一個函數庫,而"getTerm" 是帶有輸入參數"getTermRequest" 和返回參數getTermResponse 的一個函數。