http://www-128.ibm.com/developerworks/cn/webservices/ws-uwsdl/part1/
 |
 |
內(nèi)容: |
 |
|
 |
相關(guān)內(nèi)容: |
 |
|
 |
訂閱: |
 |
|
| 如何發(fā)布和查找 WSDL 服務(wù)描述
Peter Brittenham, 資深軟件工程師, IBM 新興技術(shù) Francisco Cubera, 研究人員, IBM T.J. Watson 研究中心 Dave Ehnebuske, 杰出的工程師, IBM 軟件組 Steve Graham, Web 服務(wù)體系架構(gòu)設(shè)計(jì)師, IBM 軟件組
2001 年 9 月
Web 服務(wù)描述語言(WSDL)有多種用法。特別是,根據(jù)應(yīng)用程序的需要,WSDL 在 UDDI 注冊(cè)中心有好幾種使用方法。在這第 1 篇文章中(本系列共三篇),我們將介紹一下在 UDDI 注冊(cè)中心使用 WSDL 的幾種不同的方法。
Web 服務(wù)描述語言(WSDL)是用于描述 Web 服務(wù)的一種 XML 語言,它將 Web 服務(wù)描述為一組對(duì)消息進(jìn)行操作的網(wǎng)絡(luò)端點(diǎn)。一個(gè) WSDL 服務(wù)描述包含對(duì)一組操作和消息的一個(gè)抽象定義,綁定到這些操作和消息的一個(gè)具體協(xié)議,和這個(gè)綁定的一個(gè)網(wǎng)絡(luò)端點(diǎn)規(guī)范。
統(tǒng)一描述發(fā)現(xiàn)和集成(UDDI)提供一種發(fā)布和查找服務(wù)描述的方法。UDDI 數(shù)據(jù)實(shí)體提供對(duì)定義業(yè)務(wù)和服務(wù)信息的支持。WSDL 中定義的服務(wù)描述信息是 UDDI 注冊(cè)中心信息的補(bǔ)充。UDDI 提供對(duì)許多不同類型的服務(wù)描述的支持。因此,UDDI 沒有對(duì) WSDL 的直接支持, 也沒有對(duì)任何其它服務(wù)描述機(jī)制的直接支持。
UDDI 組織,即 UDDI.org,已經(jīng)發(fā)布了一個(gè)優(yōu)化方法文檔,標(biāo)題為 在 UDDI 注冊(cè)中心 1.05 中使用 WSDL(請(qǐng)參閱 參考資料)。這個(gè)優(yōu)化方法文檔描述了關(guān)于如何在 UDDI 注冊(cè)中心發(fā)布 WSDL 服務(wù)描述的一些元素。本文的目的就是增加這種信息。主要的焦點(diǎn)問題是如何將一個(gè)完整的 WSDL 服務(wù)描述映射到 UDDI 注冊(cè)中心,現(xiàn)有的 WSDL 工具和運(yùn)行時(shí)環(huán)境要求必須做到這一點(diǎn)。本文中的信息遵守那個(gè)優(yōu)化方法文檔中列出的大致過程, 且與 WSDL 1.1、UDDI 1.0 和 UDDI 2.0 規(guī)范一致(請(qǐng)參閱 參考資料)。
UDDI 和 WSDL 概述 在描述將 WSDL 服務(wù)描述映射到 UDDI 注冊(cè)中心的過程之前,很重要的一點(diǎn)是要理解 UDDI 數(shù)據(jù)類型和主要的 WSDL 文檔類型。
UDDI 數(shù)據(jù)類型 在 UDDI 注冊(cè)中心有 4 種主要的數(shù)據(jù)類型: businessEntity、 businessService、 bindingTemplate和 tModel。 圖 1展示了所有這些數(shù)據(jù)類型之間的關(guān)系。
圖 1. UDDI 數(shù)據(jù)類型
businessEntity 提供關(guān)于商家的信息,可以包含一個(gè)或多個(gè) businessService。 這個(gè)商家是服務(wù)提供者。Web 服務(wù)的技術(shù)和業(yè)務(wù)描述在 businessService 和其 bindingTemplate 中被定義。每個(gè) bindingTemplate 包含一個(gè)對(duì)一個(gè)或多個(gè) tModel 的引用。tModel 被用于定義服務(wù)的技術(shù)規(guī)范。
WSDL 文檔類型 為幫助在 UDDI 注冊(cè)中心發(fā)布和查找 WSDL 服務(wù)描述,WSDL 文檔被分為兩種類型: 服務(wù)接口(service interface )和 服務(wù)實(shí)現(xiàn)(service implementations)(請(qǐng)參閱 圖 2)。
圖 2. WSDL 文檔類型
服務(wù)接口由 WSDL 文檔來描述,這種文檔包含服務(wù)接口的 types、 import、 message、 portType和 binding等元素。服務(wù)接口包含將用于實(shí)現(xiàn)一個(gè)或多個(gè)服務(wù)的 WSDL 服務(wù)定義。它是 Web 服務(wù)的抽象定義,并被用于描述某種特定類型的服務(wù)。
通過使用一個(gè) import 元素,一個(gè)服務(wù)接口文檔可以引用另一個(gè)服務(wù)接口文檔。 例如,一個(gè)僅包含 message 和 portType 元素的服務(wù)接口可以被另一個(gè)僅包含此 portType 的綁定的服務(wù)接口引用。
WSDL 服務(wù)實(shí)現(xiàn)文檔將包含 import和 service元素。服務(wù)實(shí)現(xiàn)文檔包含實(shí)現(xiàn)一個(gè)服務(wù)接口的服務(wù)的描述。import 元素中至少會(huì)有一個(gè)將包含對(duì) WSDL 服務(wù)接口文檔的引用。一個(gè)服務(wù)實(shí)現(xiàn)文檔可以包含對(duì)多個(gè)服務(wù)接口文檔的引用。
WSDL 服務(wù)實(shí)現(xiàn)文檔中的 import 元素包含兩個(gè)屬性。 namespace的屬性值是一個(gè)與服務(wù)接口文檔中的 targetNamespace相匹配的 URL。 location屬性是一個(gè)用于引用包含完整的服務(wù)接口定義的 WSDL 文檔的 URL。port 元素的 binding屬性包含對(duì)服務(wù)接口文檔中的某個(gè)特定綁定的引用。
服務(wù)接口文檔由 服務(wù)接口提供者開發(fā)和發(fā)布。服務(wù)實(shí)現(xiàn)文檔由 服務(wù)提供者創(chuàng)建和發(fā)布。服務(wù)接口提供者與服務(wù)提供者這兩個(gè)角色在邏輯上是分離的,但他們可以是同一個(gè)商業(yè)實(shí)體。
發(fā)布和查找 WSDL 描述 這一部分描述發(fā)布和查找一個(gè)完整的 WSDL 服務(wù)描述的過程。一個(gè)完整的 WSDL 服務(wù)描述是由一個(gè)服務(wù)接口和一個(gè)服務(wù)實(shí)現(xiàn)文檔組成的。
由于服務(wù)接口表示服務(wù)的可重用定義,它在 UDDI 注冊(cè)中心被作為 tModel 發(fā)布。 服務(wù)實(shí)現(xiàn)描述服務(wù)的實(shí)例。每個(gè)實(shí)例都是使用一個(gè) WSDL service 元素定義的。服務(wù)實(shí)現(xiàn)文檔中的每個(gè) service 元素都被用于發(fā)布 UDDI businessService。
當(dāng)發(fā)布一個(gè) WSDL 服務(wù)描述時(shí),在服務(wù)實(shí)現(xiàn)被作為 businessService 發(fā)布之前,必須將一個(gè)服務(wù)接口作為一個(gè) tModel 發(fā)布。
圖 3包含從 WSDL 到 UDDI 的映射概覽。我將在下面的部分中對(duì)這個(gè)映射加以描述。
圖 3. 從 WSDL 到 UDDI 的映射概覽
發(fā)布服務(wù)接口 在 UDDI 注冊(cè)中心,服務(wù)接口被作為 tModel 發(fā)布。tModel 由服務(wù)接口提供者發(fā)布。tModel 中的一些元素是使用來自 WSDL 服務(wù)接口描述中的信息構(gòu)建的。
UDDI tModel 表 1定義創(chuàng)建 tModel 步驟。一個(gè)有效的對(duì) WSDL 服務(wù)接口定義的 tModel 引用應(yīng)該是使用 targetNamespace 命名,并且必須包含 overviewURL 和 categoryBag 設(shè)置。
表 1: 創(chuàng)建 tModel 的步驟
|
UDDI tModel |
WSDL 服務(wù)接口 |
描述 |
必需 |
1 |
name |
definitions 元素的 targetNamespace 屬性 |
tModel 名稱使用服務(wù)接口文檔的目標(biāo)名稱空間設(shè)置。名稱需要一致以確保只使用服務(wù)實(shí)現(xiàn)文檔中的信息就可以定位 tModel。 |
是 |
2 |
description |
definitions 元素中的 documentation 元素 |
tModel description 元素被限制為只能使用 256 個(gè)字符。這個(gè)元素的英文值可根據(jù) definitions 元素的前 256 個(gè)字符設(shè)置(documentation 元素與服務(wù)接口文檔中的 definitions 元素相關(guān)聯(lián))。如果 documentation 元素不存在,那么應(yīng)該使用 definitions 元素中的 name 屬性。 |
否 |
3 |
overviewURL |
[服務(wù)接口文檔 URL 和綁定規(guī)范] |
服務(wù)接口文檔的位置必須在 overviewURL 元素中設(shè)置。如果服務(wù)接口文檔中有多個(gè)綁定,那么必須在 URL 中對(duì)綁定進(jìn)行編碼。 |
是 |
4 |
categoryBag |
[不可用] |
tModel 的 categoryBag 必須至少包含一個(gè)鍵控的引用。這個(gè)鍵控的引用必須包含一個(gè)對(duì) uddi-org:types tModel 的引用,而且鍵名必須是 wsdlSpec 。這個(gè)條目把 tModel 當(dāng)作一個(gè) WSDL 服務(wù)接口定義。 |
是 |
服務(wù)接口到 tModel 的映射示例 清單 1包含一個(gè)示例 WSDL 服務(wù)接口文檔。映射到 UDDI tModel 中的值顯示在圖表關(guān)鍵字中。 清單 1:示例 WSDL 服務(wù)接口
<?xml version="1.0"?>
<definitions name="StockQuoteService-interface"
targetNamespace="http://www.getquote.com/StockQuoteService-interface"
xmlns:tns="http://www.getquote.com/StockQuoteService-interface"
xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<documentation>
Standard WSDL service interface definition for a stock quote service.
</documentation>
<message name="SingleSymbolRequest">
<part name="symbol" type="xsd:string"/>
</message>
<message name="SingleSymbolQuoteResponse">
<part name="quote" type="xsd:string"/>
</message>
<portType name="SingleSymbolStockQuoteService">
<operation name="getQuote">
<input message="tns:SingleSymbolRequest"/>
<output message="tns:SingleSymbolQuoteResponse"/>
</operation>
</portType>
<binding name="SingleSymbolBinding"
type="tns:SingleSymbolStockQuoteService">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getQuote">
<soap:operation soapAction="http://www.getquote.com/GetQuote"/>
<input>
<soap:body use="encoded"
namespace="urn:single-symbol-stock-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:single-symbol-stock-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
</definitions>
|
關(guān)鍵字:
Definitions― targetNamespace 將被用作 tModel 的名稱。documentation 元素的內(nèi)容將被用于描述 tModel。 Binding― 綁定名將被用于限定 overviewURL。
清單 2包含在發(fā)布 WSDL 服務(wù)接口定義時(shí)創(chuàng)建的 UDDI tModel。 值顯示在圖表關(guān)鍵字中。 清單 2:根據(jù) WSDL 服務(wù)接口創(chuàng)建的 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
<name>http://www.getquote.com/StockQuoteService-interface</name>
<description xml:lang="en">
Standard service interface definition for a stock quote service.
</description>
<overviewDoc>
<description xml:lang="en">
WSDL Service Interface Document
</description>
<overviewURL>
http://www.getquote.com/services/
SQS-interface.wsdl#SingleSymbolBinding
</overviewURL>
</overviewDoc>
<categoryBag>
<keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
keyName="uddi-org:types" keyValue="wsdlSpec"/>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</tModel>
|
關(guān)鍵字:
tModel― tModel 的名稱根據(jù) targetNamespace 設(shè)置。描述是根據(jù)與 definitions 元素相關(guān)聯(lián)的 documentation 元素設(shè)置的。overviewURL 被設(shè)置為 WSDL 服務(wù)接口文檔可通過網(wǎng)絡(luò)訪問到的位置, 即 http://www.getquote.com/services/SQS-interface.wsdl。它還包含對(duì)服務(wù)接口文檔中名為的 SingleSymbolBinding 的綁定的直接引用。既然這是服務(wù)接口文檔中唯一的綁定,對(duì)綁定的這個(gè)引用就不是必需的。categoryBag 包含 wsdlSpec 條目以及其它的所有 keyedReference,keyedReference 指出這個(gè)服務(wù)接口描述的意向中的商業(yè)用途。
發(fā)布服務(wù)實(shí)現(xiàn) 服務(wù)實(shí)現(xiàn)在 UDDI 注冊(cè)中心是作為帶有一個(gè)或多個(gè) bindingTemplate 的 businessService 發(fā)布的。 businessService 由服務(wù)提供者發(fā)布。
UDDI businessService 將為服務(wù)實(shí)現(xiàn)文檔中定義的每個(gè) service 元素創(chuàng)建一個(gè)新的 businessService。 下面的表中包含 businessService 元素列表,這些 businessService 元素可根據(jù) WSDL 服務(wù)實(shí)現(xiàn)文檔的內(nèi)容創(chuàng)建。
|
UDDI businessService |
描述 |
必需 |
1 |
name |
businessService 的 name 元素根據(jù)服務(wù)實(shí)現(xiàn)文檔中的 service 元素的 name 屬性設(shè)置。 |
是 |
2 |
description |
description 元素根據(jù) service 元素中的 documentation 元素的內(nèi)容設(shè)置。 description 元素的英文值根據(jù)與 service 元素關(guān)聯(lián)的 documentation 元素中的前 256 個(gè)字符設(shè)置。如果 documentation 元素不存在,那么 businessService 的 description 元素就沒有被設(shè)置。 |
否 |
UDDI bindingTemplate 新的 bindingTemplate 元素是在 businessService 中為 service 元素中定義的每個(gè) port 元素而定義的。
|
UDDI bindingTemplate |
描述 |
必需 |
1 |
description |
如果 port 元素包含一個(gè) documentation 元素,那么就有一個(gè) description 元素是根據(jù) documentation 元素的前 256 個(gè)字符設(shè)置的。 |
否 |
2 |
accessPoint |
對(duì)于一個(gè) SOAP 或 HTTP 綁定,accessPoint 是根據(jù)與 port 元素關(guān)聯(lián)的擴(kuò)展元素的 location 屬性設(shè)置的。 這個(gè)元素將包含 URL,且 URLType 屬性是根據(jù)此 URL 中的協(xié)議設(shè)置的。對(duì)于不使用 URL 規(guī)范的協(xié)議綁定,應(yīng)該使用 URLType 屬性指出協(xié)議綁定的類型, 并且 accessPoint 元素應(yīng)該包含一個(gè)可用于定位使用指定協(xié)議的 Web 服務(wù)的值。 |
是 |
3 |
tModelInstanceInfo |
bindingTemplate 將包含自己引用的每個(gè) tModel 的一個(gè) tModelInstanceInfo 元素。至少將有一個(gè) tModelInstanceInfo 元素包含對(duì)表示服務(wù)接口文檔的 tModel 的直接引用。 |
是 |
4 |
overviewURL |
overviewURL 元素可能包含對(duì)服務(wù)實(shí)現(xiàn)文檔的一個(gè)直接引用。對(duì)這個(gè)文檔的引用僅用于提供對(duì)人類可讀的文檔的訪問。這個(gè)文檔中的其它所有信息都應(yīng)該能夠通過 UDDI 數(shù)據(jù)實(shí)體訪問。通過維持對(duì)原始 WSDL 文檔的直接引用,您可以確保被發(fā)布的文檔就是查找操作返回的那個(gè)。如果這個(gè)文檔包含多個(gè)端口,那么這個(gè)元素應(yīng)該包含對(duì)端口名的直接引用。 由于可能會(huì)有多個(gè)端口引用同一個(gè)綁定,只使用 tModel 中的直接引用是不夠的。 端口名被指定為 overviewURL 上的片段標(biāo)識(shí)符。片段標(biāo)識(shí)符是 URL 的一個(gè)擴(kuò)展,使用“#”字符作為一個(gè)分隔符。 |
否 |
服務(wù)實(shí)現(xiàn)到 businessService 的映射示例 清單 3包含 WSDL 服務(wù)實(shí)現(xiàn)文檔的一個(gè)示例。突出顯示的值是將 WSDL 信息映射到 UDDI businessService 和 bindingTemplate 時(shí)必需的值。值顯示在圖表關(guān)鍵字中。 清單 3:WSDL 服務(wù)實(shí)現(xiàn)示例
<?xml version="1.0"?>
<definitions name="StockQuoteService"
targetNamespace="http://www.getquote.com/StockQuoteService"
xmlns:interface="http://www.getquote.com/StockQuoteService-interface"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<documentation>
This service provides an implementation of a standard stock quote service.
The Web service uses the live stock quote service provided by XMLtoday.com.
The XMLtoday.com stock quote service uses an HTTP GET interface to request
a quote, and returns an XML string as a response.
For additional information on how this service obtains stock quotes, go to
the XMLtoday.com web site: http://www.xmltoday.com/examples/soap/stock.psp.
</documentation>
<import namespace="http://www.getquote.com/StockQuoteService-interface"
location="http://www.getquote.com/wsdl/SQS-interface.wsdl"/>
<service name="StockQuoteService">
<documentation>Stock Quote Service</documentation>
<port name="SingleSymbolServicePort"
binding="interface:SingleSymbolBinding">
<documentation>Single Symbol Stock Quote Service</documentation>
<soap:address location="http://www.getquote.com/stockquoteservice"/>
</port>
</service>
</definitions>
|
關(guān)鍵字:
Service― service 元素的 name 屬性被用作 businessService 的名稱。service 元素中的 documentation 元素被用于描述 businessService。 Import― 端口名被附加到 overviewURL,此 overviewURL 包含對(duì)服務(wù)實(shí)現(xiàn)文檔的引用。服務(wù)的位置被用于設(shè)置 bindingTemplate 中的 accessPoint。
清單 4包含根據(jù)服務(wù)實(shí)現(xiàn)文檔創(chuàng)建的 UDDI businessService 定義。categoryBag 應(yīng)該包含一個(gè)或多個(gè) keyedReference,它們被用于對(duì)服務(wù)意向中的商業(yè)用途進(jìn)行分類。值顯示在圖表關(guān)鍵字中。 清單 4:根據(jù) WSDL 服務(wù)實(shí)現(xiàn)創(chuàng)建的 UDDI 商業(yè)服務(wù)
<businessService businessKey="..." serviceKey="...">
<name>StockQuoteService</name>
<description xml:lang="en">
Stock Quote Service
</description>
<bindingTemplates>
<bindingTemplate bindingKey="..." serviceKey="...">
<description>
Single Symbol Stock Quote Service
</description>
<accesssPoint URLType="http">
http://www.getquote.com/singlestockquote
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey="[tModel Key for Service Interface]">
<instanceDetails>
<overviewURL>
http://www.getquote.com/services/SQS.wsdl
</overviewURL>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
</bindingTemplates>
<categoryBag>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</businessService>
|
關(guān)鍵字:
BusinessService― businessService 的 name 根據(jù) WSDL 服務(wù)實(shí)現(xiàn)文檔中的 service 的 name設(shè)置。 description 根據(jù) service 元素中的 documentation 元素設(shè)置。 BindingTemplate― 它的 description 是根據(jù) port 元素中的documentation 元素設(shè)置。accessPoint 根據(jù) soap:address 擴(kuò)展元素設(shè)置。tModelKey 被設(shè)置到與服務(wù)接口文檔關(guān)聯(lián)的 tModel 的 UUID。可使用 import 元素的 namespace 屬性對(duì) tModel 進(jìn)行定位。overviewURL 是服務(wù)實(shí)現(xiàn)文檔的位置。 由于它是這個(gè)文檔中唯一的引用,它不包含對(duì) SingleServiceQuote 端口的引用。
查找 WSDL 服務(wù)接口描述 所有的 WSDL 服務(wù)接口在 UDDI 注冊(cè)中心都是作為 tModel 發(fā)布。對(duì)這些 tModel 中的每一個(gè)都要進(jìn)行歸類,以便將它們標(biāo)識(shí)為 WSDL 服務(wù)描述。UDDI find_tModel 消息可用于查找已經(jīng)分過類的 tModel。使用 UDDI V1.0 API 時(shí), 清單 5中列出的 find_tModel 消息可用于定位所有的 WSDL 服務(wù)接口描述。 清單 5:查找 WSDL 服務(wù)接口描述
<?xml version="1.0"?>
<find_tModel generic="1.0" xmlns="urn:uddi-org:api">
<categoryBag>
<keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
keyName="uddi-org:types" keyValue="wsdlSpec"/>
</categoryBag>
</find_tModel>
|
find_tModel 消息將返回一列 tModel 關(guān)鍵字。使用 get_tModelDetail 消息可檢索特定的服務(wù)接口描述。get_tModelDetail 消息將返回一個(gè) tModel, 比如 清單 2中列出的那個(gè)。
在檢索了一個(gè) tModel 后,可使用 overviewURL 檢索 WSDL 服務(wù)接口文檔的內(nèi)容。
可將另外的 keyedReference 添加到 categoryBag 以限制這個(gè)查找請(qǐng)求的響應(yīng)中返回的 tModel 集。 清單 6中的 find_tModel 消息可用于定位使用 WSDL 定義的所有股票報(bào)價(jià)服務(wù)。 清單 6:查找期望的商業(yè)用途的 WSDL 服務(wù)接口
<?xml version="1.0"?>
<find_tModel generic="1.0" xmlns="urn:uddi-org:api">
<categoryBag>
<keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
keyName="uddi-org:types" keyValue="wsdlSpec"/>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</find_tModel>
|
查找 WSDL 服務(wù)實(shí)現(xiàn)描述 WSDL 服務(wù)實(shí)現(xiàn)在 UDDI 注冊(cè)中心是作為 businessService 發(fā)布的。businessService 將包含一個(gè)或多個(gè) bindingTemplate。對(duì) businessService 進(jìn)行歸類,以便將它看作基于 WSDL 的服務(wù)描述。使用 UDDI V1.0 API 時(shí),必須找到一個(gè) businessEntity 或一個(gè) businessEntity 集才能使用 businessService 的查找 API。同樣地,也必須找到一個(gè) businessService 或一個(gè) businessService 集才能使用查找 API 定位 bindingTemplate。
查找 UDDI businessService 有兩種基本方法可用于查找服務(wù)描述。使用特定的分類法,UDDI find_service 消息可用于查找服務(wù)描述,或者說它可用于查找實(shí)現(xiàn)某個(gè)特定的服務(wù)接口的服務(wù)描述。
使用 UDDI V1.0 API 時(shí),可為某個(gè)特定的 businessEntity 發(fā)出 清單 7中的消息,以便定位股票報(bào)價(jià)服務(wù)實(shí)現(xiàn)這個(gè) businessService??蓪⒘硗獾?keyedReference 添加到 categoryBag 以縮小對(duì)此消息的響應(yīng)中返回的服務(wù)描述的范圍。 清單 7:查找 WSDL 服務(wù)實(shí)現(xiàn)描述
<?xml version="1.0"?>
<find_service businessKey="..." generic="1.0" xmlns="urn:uddi-org:api">
<categoryBag>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</find_service>
|
find_service 消息也可用于定位 businessService ― 該 businessService 是某個(gè)特定服務(wù)接口的實(shí)現(xiàn)。 清單 8中的消息包含 find_service 消息的一個(gè)示例,它將查找 businessEntity 中的所有 businessService,這個(gè) businessEntity 實(shí)現(xiàn)了股票報(bào)價(jià)服務(wù)的服務(wù)接口。由于服務(wù)接口是用 tModel 來表示,tModelBag 就被用于指定 WSDL 服務(wù)接口與股票報(bào)價(jià)服務(wù)相關(guān)聯(lián)的 tModel 關(guān)鍵字。 清單 8:使用 tModelBag 查找 WSDL 服務(wù)實(shí)現(xiàn)描述
<?xml version="1.0"?>
<find_service businessKey="..." generic="1.0" xmlns="urn:uddi-org:api">
<tModelBag>
<tModelKey>[tModel key for WSDL service interface]</tModelKey>
</tModelBag>
</find_service>
|
find_service 消息將返回一列服務(wù)關(guān)鍵字??墒褂?get_serviceDetail 消息檢索 businessService 描述。get_serviceDetail 消息將返回一個(gè) businessService,比如 清單 4中的那個(gè)。
檢索了一個(gè) businessService 后,可選擇某個(gè)特定的 bindingTemplate 調(diào)用 Web 服務(wù)。bindingTemplate 中的 accessPoint 是服務(wù)的端點(diǎn)。overviewURL 可用于檢索 WSDL 服務(wù)實(shí)現(xiàn)文檔的內(nèi)容,該文檔可能包含關(guān)于已實(shí)現(xiàn)服務(wù)的額外詳細(xì)信息。
查找 UDDI bindingTemplate 如果 businessService 包含多個(gè) bindingTemplate,可能會(huì)很難確定要使用哪個(gè) bindingTemplate。 find_binding 消息可用于定位應(yīng)該使用的 bindingTemplate。
清單 9包含一條 find_binding 消息,可用它來檢索引用特定的 tModel 的 bindingTemplate??蓪⑦@個(gè) tModel 與 WSDL 服務(wù)接口描述中的特定綁定關(guān)聯(lián)起來。 清單 9:查找 UDDI bindingTemplate
<?xml version="1.0"?>
<find_binding serviceKey="..." generic="1.0" xmlns="urn:uddi-org:api">
<tModelBag>
<tModelKey>[tModelKey for WSDL service interface]<tModelKey/>
</tModelBag>
</find_service>
|
這條消息將返回一個(gè)或多個(gè) bindingTemplate,比如 清單 10中的那個(gè)。訪問過 bindingTemplate 之后,accessPoint 中列出了 Web 服務(wù)的端點(diǎn)。 如果 bindingTemplate 是根據(jù)現(xiàn)有的 WSDL 服務(wù)實(shí)現(xiàn)文檔創(chuàng)建的,那么 overviewURL 可能包含一個(gè)對(duì)這個(gè)文檔的引用??稍L問這個(gè)文檔獲取額外的、人類可讀的關(guān)于 Web 服務(wù)的信息, 這些信息在 UDDI 注冊(cè)中心找不到。 清單 10:UDDI bindingTemplate
<?xml version="1.0"?>
<bindingTemplate bindingKey="" serviceKey="">
<accesssPoint URLType="http">
http://www.getquote.com/singlestockquote
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey="[tModel Key for Service Interface]">
<instanceDetails>
<overviewURL>
http://www.getquote.com/services/SQS.wsdl
</overviewURL>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
|
總結(jié) 本文已經(jīng)描述了在 UDDI 注冊(cè)中心發(fā)布和查找完整的 WSDL 服務(wù)描述的過程。WSDL 服務(wù)接口描述是作為 UDDI tModel 發(fā)布的,而 WSDL 服務(wù)實(shí)現(xiàn)描述是作為 UDDI businessService 發(fā)布的。 圖 4提供了從 WSDL 服務(wù)接口和服務(wù)實(shí)現(xiàn)文檔到 UDDI 注冊(cè)中心條目的映射概覽。
在本系列的下一篇文章中,我們將討論在開發(fā)者經(jīng)常遇到的 5 種不同情形下在 UDDI 注冊(cè)中心使用 WSDL 所需的精確代碼。
圖 4:從 WSDL 到 UDDI 的映射概覽
在本系列的下一篇文章中,我們將對(duì)不同的 WSDL 用法個(gè)案研究應(yīng)用本文中描述的過程。 每個(gè)用法個(gè)案研究都將舉例說明應(yīng)該如何在 UDDI 注冊(cè)中心發(fā)布不同類型的 WSDL 服務(wù)描述。
參考資料
作者簡(jiǎn)介 Peter Brittenham 目前是 IBM Web Services Toolkit的首席體系架構(gòu)設(shè)計(jì)師。Web Services Toolkit 包含使用 SOAP 和 WSDL 構(gòu)建 Web 服務(wù)所需的工具和運(yùn)行時(shí)支持,以及在 UDDI 注冊(cè)中心發(fā)布和查找服務(wù)定義的運(yùn)行時(shí)支持??赏ㄟ^ peterbr@us.ibm.com與他聯(lián)系。 |
Francisco Curbera 是 IBM TJ Watson 研究中心的一個(gè)研究人員,他于 1993 加入該研究中心。他主要致力于組件軟件開發(fā)以及基于標(biāo)準(zhǔn)的分布式計(jì)算應(yīng)用框架的設(shè)計(jì)和實(shí)現(xiàn)。他是 Web 服務(wù)描述語言(WSDL)的合作者之一,還為 Web 服務(wù)領(lǐng)域的其它幾個(gè)規(guī)范的定義和實(shí)現(xiàn)做出了貢獻(xiàn)。他從西班牙 Universidad Complutense de Madrid 大學(xué)獲得了物理學(xué)理科碩士學(xué)位,并從哥倫比亞大學(xué)獲得了計(jì)算機(jī)科學(xué)博士學(xué)位。可通過 curbera@us.ibm.com與他聯(lián)系。
|
Dave Ehnebuske 是 IBM 的軟件組中的一位杰出的工程師, 負(fù)責(zé)應(yīng)用集成和中間件的開發(fā)。他是 SOAP 1.1 的合著者之一,同時(shí)還是 W3C XML 協(xié)議工作組的成員,這個(gè)組的主要工作是對(duì) SOAP 進(jìn)行標(biāo)準(zhǔn)化。可通過 davide@us.ibm.com與他聯(lián)系。
|
Steve Graham 是 IBM 軟件組的新興技術(shù)分部的一位體系架構(gòu)設(shè)計(jì)師。他在前幾年一直從事面向服務(wù)的體系結(jié)構(gòu),最近還成了 IBM Web Services Initiative 的一員。在此之前,Steve 擔(dān)任各種新興技術(shù)如 Java 和 XML 的技術(shù)專家和顧問,此前他還是IBM Smalltalk 咨詢小組中的體系架構(gòu)設(shè)計(jì)師和顧問。 在加入 IBM 之前,Steve 曾是 Sybase 開發(fā)者、顧問和 Waterloo 大學(xué)計(jì)算機(jī)科學(xué)系的教員。Steve 持有 Waterloo 大學(xué)的計(jì)算機(jī)科學(xué)的 BMath 和 MMAth。可通過 sggraham@us.ibm.com與他聯(lián)系。
| |