WSDL 文檔
WSDL 文檔僅僅是一個簡單的 XML 文檔。
它包含一系列描述某個 web service 的定義。
WSDL 文檔結構
WSDL 文檔是利用這些主要的元素來描述某個 web service 的:
元素 | 定義 |
---|---|
<portType> | web service 執行的操作 |
<message> | web service 使用的消息 |
<types> | web service 使用的數據類型 |
<binding> | web service 使用的通信協議 |
一個 WSDL 文檔的主要結構是類似這樣的:
<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 文檔的簡化的片段:
<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 的一個函數。