定義
WSDL 是基于 XML 的用于描述 Web Services 以及如何訪問 Web Services 的語言嫩挤。
WSDL 特性
- WSDL 指網(wǎng)絡(luò)服務(wù)描述語言
- WSDL 使用 XML 編寫
- WSDL 是一種 XML 文檔
- WSDL 用于描述網(wǎng)絡(luò)服務(wù)
- WSDL 也可用于定位網(wǎng)絡(luò)服務(wù)
- WSDL 還不是 W3C 標準
WSDL 作用
WSDL 指網(wǎng)絡(luò)服務(wù)描述語言 (Web Services Description Language)。
WSDL 是一種使用 XML 編寫的文檔隅忿。這種文檔可描述某個 Web service。它可規(guī)定服務(wù)的位置,以及此服務(wù)提供的操作(或方法)拇泛。
WSDL 文檔結(jié)構(gòu)
WSDL 文檔是利用這些主要的元素來描述某個 web service 的:
元素 | 定義 |
---|---|
<portType> | web service 執(zhí)行的操作 |
<message> | web service 使用的消息 |
<types> | web service 使用的數(shù)據(jù)類型 |
<binding> | web service 使用的通信協(xié)議 |
一個 WSDL 文檔的主要結(jié)構(gòu)是類似這樣的:
<definitions>
<types>
definition of types........
</types>
<message>
definition of a message....
</message>
<portType>
definition of a port.......
</portType>
<binding>
definition of a binding....
</binding>
</definitions>
WSDL 文檔可包含其它的元素,比如 extension 元素须板,以及一個 service 元素碰镜,此元素可把若干個 web services 的定義組合在一個單一的 WSDL 文檔中。
WSDL 端口
<portType> 元素是最重要的 WSDL 元素习瑰。
它可描述一個 web service绪颖、可被執(zhí)行的操作,以及相關(guān)的消息甜奄。
可以把 <portType> 元素比作傳統(tǒng)編程語言中的一個函數(shù)庫(或一個模塊柠横、或一個類)。
WSDL 消息
<message> 元素定義一個操作的數(shù)據(jù)元素课兄。
每個消息均由一個或多個部件組成牍氛。可以把這些部件比作傳統(tǒng)編程語言中一個函數(shù)調(diào)用的參數(shù)烟阐。
WSDL types
<types> 元素定義 web service 使用的數(shù)據(jù)類型搬俊。
為了最大程度的平臺中立性,WSDL 使用 XML Schema 語法來定義數(shù)據(jù)類型蜒茄。
WSDL Bindings
<binding> 元素為每個端口定義消息格式和協(xié)議細節(jié)唉擂。
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> 元素可定義每個消息的部件空扎,以及相關(guān)聯(lián)的數(shù)據(jù)類型藏鹊。
對比傳統(tǒng)的編程,glossaryTerms 是一個函數(shù)庫转锈,而 "getTerm" 是帶有輸入?yún)?shù) "getTermRequest" 和返回參數(shù) getTermResponse 的一個函數(shù)盘寡。
WSDL 端口 操作類型
類型 | 定義 |
---|---|
One-way | 此操作可接受消息,但不會返回響應(yīng)黑忱。 |
Request-response | 此操作可接受一個請求并會返回一個響應(yīng) |
Solicit-response | 此操作可發(fā)送一個請求宴抚,并會等待一個響應(yīng)。 |
Notification | 此操作可發(fā)送一條消息甫煞,但不會等待響應(yīng)菇曲。 |
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" 操作可接受新術(shù)語表項目消息的輸入常潮,這些消息使用一條名為 "newTermValues" 的消息,此消息帶有輸入?yún)?shù) "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" 的參數(shù)检柬,并將返回一個名為 "getTermResponse" 的輸出消息献联,此消息帶有一個名為 "value" 的參數(shù)。
綁定到 SOAP
一個 請求 - 響應(yīng) 操作的例子:
<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 屬性和 transport 屬性原押。
style 屬性可取值 "rpc" 或 "document"。在這個例子中我們使用 document偎血。transport 屬性定義了要使用的 SOAP 協(xié)議诸衔。在這個例子中我們使用 HTTP。
operation 元素定義了每個端口提供的操作符颇玷。
對于每個操作署隘,相應(yīng)的 SOAP 行為都需要被定義。同時您必須如何對輸入和輸出進行編碼亚隙。在這個例子中我們使用了 "literal"
UDDI
定義
UDDI 是一種目錄服務(wù),企業(yè)可以使用它對 Web services 進行注冊和搜索违崇。
UDDI阿弃,英文為 "Universal Description, Discovery and Integration"诊霹,可譯為“通用描述、發(fā)現(xiàn)與集成服務(wù)”渣淳。
UDDI 特性
- UDDI 指的是通用描述脾还、發(fā)現(xiàn)與集成服務(wù)
- UDDI 是一種用于存儲有關(guān) web services 的信息的目錄。
- UDDI 是一種由 WSDL 描述的 web services 界面的目錄入愧。
- UDDI 經(jīng)由 SOAP 進行通信
- UDDI 被構(gòu)建入了微軟的 .NET 平臺
UDDI 基于什么鄙漏?
UDDI 使用 W3C 和 IETF* 的因特網(wǎng)標準,比如 XML棺蛛、HTTP 和 DNS 協(xié)議怔蚌。
UDDI 使用 WSDL 來描述到達 web services 的界面
此外,通過采用 SOAP旁赊,還可以實現(xiàn)跨平臺的編程特性桦踊,大家知道,SOAP 是 XML 的協(xié)議通信規(guī)范终畅,可在 W3C 的網(wǎng)站找到相關(guān)的信息籍胯。
*注釋:IETF - Internet Engineering Task Force
UDDI 的好處
任何規(guī)模的行業(yè)或企業(yè)都能得益于 UDDI。
在 UDDI 之前离福,還不存在一種 Internet 標準杖狼,可以供企業(yè)為它們的企業(yè)和伙伴提供有關(guān)其產(chǎn)品和服務(wù)的信息。也不存在一種方法妖爷,來集成到彼此的系統(tǒng)和進程中蝶涩。
- 使得在成百萬當(dāng)前在線的企業(yè)中發(fā)現(xiàn)正確的企業(yè)成為可能
- 定義一旦首選的企業(yè)被發(fā)現(xiàn)后如何啟動商業(yè)
- 擴展新客戶并增加對目前客戶的訪問
- 擴展銷售并延伸市場范圍
- 滿足用戶驅(qū)動的需要,為在全球 Internet 經(jīng)濟中快速合作的促進來清除障礙
UDDI 如何被使用
假如行業(yè)發(fā)布了一個用于航班比率檢測和預(yù)訂的 UDDI 標準赠涮,航空公司就可以把它們的服務(wù)注冊到一個 UDDI 目錄中子寓。然后旅行社就能夠搜索這個 UDDI 目錄以找到航空公司預(yù)訂界面。當(dāng)此界面被找到后笋除,旅行社就能夠立即與此服務(wù)進行通信斜友,這樣由于它使用了一套定義良好的預(yù)訂界面。