WSDL 端口


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


WSDL 端口

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

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

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


操作類型

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

類型 定義
One-way 此操作可接受消息,但不會返回回應。
Request-response 此操作可接受一個請求並會返回一個回應
Solicit-response 此操作可發送一個請求,並會等待一個回應。
Notification 此操作可發送一條消息,但不會等待回應。


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"。不過,沒有為這個操作定義任何輸出。


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" 的參數。