http://www-128.ibm.com/developerworks/cn/webservices/ws-uwsdl/part2/index.html
發布和查找 WSDL 服務描述的用法個案研究
Peter Brittenham
資深軟件工程師, IBM 新興技術
2001 年 9 月
如這個系列的第 1 篇文章說明的那樣,“Web 服務描述語言”(Web Services Description Language(WSDL))的多功能性使得在 UDDI 注冊中心使用它更加復雜。在本文,即本系列第 2 部分中,Peter 使用各種 WSDL 用法個案研究來實現將 WSDL 映射到 UDDI 環境的過程。
如本系列的第 1 部分所述(請參閱 參考資料),一個完整的 WSDL 服務描述由服務接口和服務實現組成。這些服務描述中的每一個都可以駐留在不同的物理 WSDL 文檔中。
本系列的這一部分包含在“UDDI 注冊中心”發布和查找完整的 WSDL 服務描述的用法個案研究。對于每一個用法個案研究,我將描述一個在 UDDI 注冊中心發布完整的 WSDL 服務定義的方法。對這些方法的描述根據的是 UDDI 優化方法文檔中的過程以及“UDDI 程序員的 API 規范”和“UDDI 數據結構參考大全”中定義的用法約定(請參閱 參考資料)。
個案研究 1:沒有服務實現的服務接口
當服務接口提供者將 WSDL 服務接口定義作為 tModel 發布時,將可以從任意 UDDI businessService 引用這個 tModel。這個個案研究展示如何發布一個帶有對 tModel(此 tModel 與 WSDL 服務接口相關聯)的引用的 businessService。在這個個案研究中,UDDI businessService 與 WSDL 服務實現定義無關。可以使用 UDDI 優化方法文檔中描述的過程實現這個個案研究。
WSDL 服務接口定義
服務接口文檔包含所有的 WSDL 類型、message、portType 和 binding 元素。在這個個案研究中,Web 服務包含一個操作,使用 SOAP 指定綁定。這個示例并不包括 types 元素,因為這個用法個案研究不要求消息的數據類型定義。
清單 1包含一個簡單服務接口文檔示例。突出顯示的域將在 UDDI 數據實體中被引用。
清單 1: 個案研究 1 簡單服務接口文檔
<?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>
|
發布 UDDI tModel
WSDL 服務接口描述由服務接口提供者發布。發布了這個文檔后,服務提供者才可以發布一個引用服務接口的 businessService。這個服務接口被作為 tModel 發布,將包含一個對 WSDL 服務接口文檔的引用。
清單 2包含發布上面列出的服務接口時創建的 tModel。
清單 2:個案研究 1 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
<name>http://www.getquote.com/StockQuoteService-interface</name>
<description xml:lang="en">
Standard WSDL 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>
|
發布 UDDI businessService
實現這個服務接口的服務提供者可以發布一個引用與服務接口相關聯的 tModel 的 businessService 描述。不必使用 WSDL 指定服務實現的服務描述。
清單 3:個案研究 1 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
<name>StockQuoteService</name>
<description xml:lang="en">
Stock Quote Service
</description>
<bindingTemplates>
<bindingTemplate bindingKey="" serviceKey="">
<description>
Single Symbol Service
<description>
<accessPoint URLType="http">
http://www.getquote.com/stockquoteservice
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey="[tModel Key for Service Interface]">
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
</bindingTemplates>
<categoryBag>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</businessService>
|
構建一個 WSDL 服務實現文檔
既然 UDDI businessService 不是根據 WSDL 服務實現文檔創建的,那么需要 WSDL 的工具或運行時組件將不得不根據 businessService 和被它的 bindingTemplates 引用的 tModel 的內容構建一個 WSDL 文檔。
清單 4包含一個 WSDL 服務實現文檔,該文檔是根據這個個案研究的 UDDI businessService 的內容創建的。值顯示在圖表鍵中。
清單 4:個案研究 1 根據 UDDI businessService 創建的 WSDL 服務實現
<?xml version="1.0"?>
<definitions name="StockQuoteService"
xmlns:interface1="http://www.getquote.com/StockQuoteService-interface"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<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="StockQuoteServicePort"
binding="interface1:SingleSymbolBinding">
<documentation>Single Symbol Service</documentation>
<soap:address location="http://www.getquote.com/stockquoteservice"/>
</port>
</service>
</definitions>
|
關鍵字:
Definitions― definitions 元素的 name 屬性根據 businessService 名稱設置。XML 模式、WSDL、SOAP 綁定、HTTP 綁定和 MIME 綁定的 XML 名稱空間引用被添加到 definitions 元素。
Import― 一個 import 元素是為一個引用 WSDL 服務接口文檔的 tModel 創建的。tModel 關鍵字被用于獲取 tModel 詳細信息。tModel 包含引用 WSDL 服務接口文檔的 overviewURL。namespace 屬性使用 WSDL 服務接口文檔中的 targetNamespace 來設置。location 屬性使用與服務接口定義相關聯的 tModel 內 overviewURL 中的值來設置。對于每個 import 元素,XML 名稱空間引用都要被添加到 definitions 元素中,方法是使用服務接口文檔中的 targetNamespace。
Service― service 元素的 name 屬性根據 businessService 名稱設置。因為服務名稱是一個 NCName,所以必須修改 businessService 名稱以獲取適當的 WSDL 服務名稱。service 元素中的 documentation 元素根據 businessService 描述設置。
Port― 一個 port 元素是為 businessService(此 businessService 引用使用 WSDL 描述的服務)中的一個 bindingTemplate 創建的。port 元素的 name 屬性被設置為服務名稱,并附加字符串“Port”。為了設置 binding 屬性,綁定引用是從 tModel 中的 overviewURL 獲取的。如果沒有指定綁定是在 overviewURL 上,那么 WSDL 服務接口中的第 1 個綁定被用于設置綁定名稱。因為 binding 屬性是一個 QName,所以用服務接口引用的 XML 名稱空間規范作為綁定名稱的前綴。如果 bindingTemplate 包含一個描述,那么它將被用于設置 port 元素中的 documentation 元素。port 元素中的 extension 元素是根據綁定類型創建的。對于一個 SOAP 綁定,使用 soap:address 元素。extension 元素的 location 屬性根據 bindingTemplate 中的 accessPoint 設置。
個案研究 2:帶有一個服務接口文檔的服務實現
服務接口可以由一個人來開發,然后由另一個人來實現和引用。對于那些只對 WSDL 服務描述進行操作的一組工具或運行時組件,WSDL 服務實現文檔將包含對 WSDL 服務接口文檔的一個引用。在這個個案研究中,服務實現文檔只引用一個 WSDL 服務接口文檔。
WSDL 服務接口定義
這個個案研究的服務接口定義與 UDDI 優化方法文檔中描述的那個服務接口定義一致。服務接口文檔包含所有的 WSDL 類型、message、portType 和 binding 元素。
清單 5包含一個簡單服務接口文檔示例。這個文檔中描述的服務包含一個操作,使用 SOAP 指定綁定。突出顯示的域將在 UDDI 數據實體中被引用。
清單 5:個案研究 2 WSDL 服務接口文檔
<?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 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>
|
發布 UDDI tModel
必須在服務接口提供者發布服務接口描述之后,才可以發布服務實現描述。這個服務接口被作為 tModel 發布。這個 tModel 將包含對 WSDL 服務接口文檔的引用。
清單 6包含發布上面列出的服務接口時創建的 tModel。
清單 6:個案研究 2 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>
|
WSDL 服務實現定義
服務實現文檔包含一個引用服務接口文檔的 import 元素和一個包含對 Web 服務位置的引用的 service 元素。 清單 7包含這種類型 WSDL 文檔的一個示例
清單 7:個案研究 2 WSDL 服務實現定義
<?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/">
<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="SingleSymbolService"
binding="interface:SingleSymbolBinding">
<soap:address location="http://www.getquote.com/stockquoteservice"/>
</port>
</service>
</definitions>
|
發布 UDDI businessService
WSDL 服務實現描述由服務提供者發布。服務實現被作為 businessService 發布。與服務接口相關聯的 tModel 被 businessService 內的 bindingTemplate 引用。
這個發布服務實現的方法不是在 UDDI 優化方法文檔中定義的。UDDI 優化方法文檔第 7 頁的“Publishing Service Implementations”包含對如何根據 WSDL 服務實現文檔創建 businessService 的描述。
清單 8包含根據上面列出的服務實現創建的一個 businessService 的示例。
清單 8:個案研究 2 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
<name>StockQuoteService</name>
<description xml:lang="en">
Stock Quote Service
</description>
<bindingTemplates>
<bindingTemplate bindingKey="" serviceKey="">
<accesssPoint URLType="http">
http://www.getquote.com/stockquoteservice
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey="[tModel Key for Service Interface]">
<instanceDetails>
<overviewURL>
http://www.getquote.com/services/SQS.wsdl#SingleSymbolService
</overviewURL>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
</bindingTemplates>
<categoryBag>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</businessService>
|
個案研究 3:帶有多個服務接口文檔的服務實現
一個服務提供者可能決定開發一個實現多個服務接口定義的 Web 服務。這個 Web 服務的 WSDL 服務實現文檔將包含對全部服務接口文檔的引用。對服務接口文檔的每個引用都是用服務實現文檔中的 import 元素表示。
WSDL 服務接口定義
對于這個個案研究,有兩個不同的服務接口。這兩個服務接口可以由同一個服務接口提供者發布,也可以由不同的服務接口提供者發布。每個服務接口文檔包含不同的目標名稱空間、端口類型和綁定。而且,每個 SOAP 綁定引用一個不同的 SOAP 服務。
下面的圖包含一個服務的服務接口定義,這個服務要求一個股票符號作為輸入消息,一個股票報價作為響應。
清單 9:個案研究 3 第一個 WSDL 服務接口
<?xml version="1.0"?>
<definitions name="StockQuoteService-SingleSymbol-interface"
targetNamespace="http://www.getquote.com/StockQuoteService-SingleSymbol-interface"
xmlns:tns="http://www.getquote.com/StockQuoteService-SingleSymbol-interface"
xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<documentation>
Standard service interface definition for a stock quote service that
has only one symbol as an input parameter.
</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-symobl-stock-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
</definitions>
|
清單 10包含一個服務接口定義,該定義可以擁有多個股票符號作為輸入消息,多個股票報價作為響應。這個服務接口包含自己的消息(message)、端口類型(portType)和綁定(binding)規范。
清單 10:個案研究 3 第二個 WSDL 服務接口
<?xml version="1.0"?>
<definitions name="StockQuoteService-MultSymbol-interface"
targetNamespace="http://www.getquote.com/StockQuoteService-MultSymbol-interface"
xmlns:tns="http://www.getquote.com/StockQuoteService-MultSymbol-interface"
xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
xmlns:xsd1="http://http://www.getquote.com/StockQuoteService/schema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<documentation>
Standard service interface definition for a stock quote service that
can receive a request that contains multiple symbols.
</documentation>
<types>
<schema targetNamespace="http://www.getquote.com/StockQuoteService/schema"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<complexType name="ArrayOfString">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref=soapenc:arrayType
wsdl:arrayType="xsd:string[]"/>
</restriction>
</complexContent>
</compextType>
</schemas>
</types>
<message name="MultSymbolRequest">
<part name="symbols" type="xsd1:ArrayOfString"/>
</message>
<message name="MultSymbolQuoteResponse">
<part name="quotes" type="xsd1:ArrayOfString"/>
</message>
<portType name="MultSymbolStockQuoteService">
<operation name="getQuotes">
<input message="tns:MultSymbolRequest"/>
<output message="tns:MultSymbolQuoteResponse"/>
</operation>
</portType>
<binding name="MultSymbolBinding"
type="tns:MultSymbolStockQuoteService">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getQuotes">
<soap:operation soapAction="http://www.getquote.com/GetQuotes"/>
<input>
<soap:body use="encoded"
namespace="urn:mult-symbol-stock-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:mult-symbol-stock-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
|
發布 UDDI tModel
這個個案研究的兩個 WSDL 服務接口都將在 UDDI 注冊中心被作為單獨的 tModel 發布。既然每個服務接口只包含一個綁定,overviewURL 就不需要引用一個特定綁定。 清單 11包含描述第一個服務接口定義的 tModel。
清單 11:個案研究 3 第一個 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
<name>http://www.getquote.com/StockQuoteService-SingleSymbol-interface</name>
<description xml:lang="en">
Standard service interface definition for a stock quote service that
has only one symbol as an input parameter.
</description>
<overviewDoc>
<description xml:lang="en">
WSDL Service Interface Document
</description>
<overviewURL>
http://www.getquote.com/services/SQS-SingleSymbol-interface.wsdl
</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>
|
清單 12包含第二個服務接口定義的 tModel
清單 12:個案研究 3 第二個 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
<name>http://www.getquote.com/StockQuoteService-MultSymbol-interface</name>
<description xml:lang="en">
Standard service interface definition for a stock quote service that
can receive a request that contains multiple symbols.
</description>
<overviewDoc>
<description xml:lang="en">
WSDL Service Interface Document
</description>
<overviewURL>
http://www.getquote.com/services/SQS-MultSymbol-interface.wsdl
</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>
|
WSDL 服務實現定義
這個個案研究的 WSDL 服務實現文檔將包含兩個 import 元素。每個 import 元素將引用其中一個服務接口文檔。這個文檔還包含至少兩個 port 元素。每個 port 元素從其中一個服務接口文檔的內部引用一個綁定。
清單 13:個案研究 3 WSDL 服務實現
<definitions name="StockQuoteService"
targetNamespace="http://www.getquote.com/StockQuoteService"
xmlns:single="http://www.getquote.com/StockQuoteService-SingleSymbol-interface"
xmlns:mult="http://www.getquote.com/StockQuoteService-MultSymbol-interface"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<import
namespace="http://www.getquote.com/StockQuoteService-SingleSymbol-interface"
location="http://www.getquote.com/wsdl/SQS-SingleSymbol-interface.wsdl"/>
<import
namespace="http://www.getquote.com/StockQuoteService-MultSymbol-interface"
location="http://www.getquote.com/wsdl/SQS-MultSymbol-interface.wsdl"/>
<service name="StockQuoteService">
<documentation>Stock Quote Service</documentation>
<port name="SingleSymbolService"
binding="single:SingleSymbolBinding">
<soap:address location="http://www.getquote.com/stockquoteservice"/>
</port>
<port name="MultSymbolService"
binding="mult:MultSymbolBinding">
<soap:address location="http://www.getquote.com/stockquoteservice"/>
</port>
</service>
</definitions>
|
發布 UDDI businessService
對于這個個案研究,服務提供者開發了一個對兩個服務接口都實現的服務。服務實現描述由服務提供者作為 UDDI businessService 發布。因為一個服務實現使用不同的 import 元素引用多個服務接口,所以 businessService 中的每個 bindingTemplate 將引用不同的 tModel。
這個發布服務實現的方法不是在 UDDI 優化方法文檔中定義的。UDDI 優化方法文檔第 7 頁的“Publishing Service Implementations”包含對如何根據 WSDL 服務實現文檔創建 businessService 的描述。
清單 14包含根據上面列出的服務實現創建的一個 businessService 的示例
清單 14:個案研究 3 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
<name>StockQuoteService</name>
<description xml:lang="en">
Stock Quote Service
</description>
<bindingTemplates>
<bindingTemplate bindingKey="" serviceKey="">
<accesssPoint URLType="http">
http://www.getquote.com/stockquoteservice
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey="[tModel Key for Service Interface 1]">
<instanceDetails>
<overviewURL>
http://www.getquote.com/services/SQS.wsdl#SingleSymbolService
</overviewURL>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
<bindingTemplate bindingKey="" serviceKey="">
<accesssPoint URLType="http">
http://www.getquote.com/stockquoteservice
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey="[tModel Key for Service Interface 2]">
<instanceDetails>
<overviewURL>
http://www.getquote.com/services/SQS.wsdl#MultSymbolService
</overviewURL>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
</bindingTemplates>
<categoryBag>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</businessService>
|
個案研究 4:單個 WSDL 文檔
如果服務接口提供者和服務提供者是同一個人,那么一個 WSDL 文檔就可用于定義一個完整的 WSDL 服務描述。這個個案研究的目的是展示 UDDI businessService 和 tModel 可以從它們各自的 overviewURL 元素引用相同的文檔。
一個 WSDL 文檔被既作為 UDDI tModel,又作為 businessService 發布。這些數據實體都將包含對同一個 WSDL 文檔的引用。
單個 WSDL 服務定義
清單 15包含一個包含完整的服務定義的 WSDL 文檔示例。這個文檔包含完整地描述一個 Web 服務所需的全部 WSDL 元素。將服務接口定義和服務實現定義組合成一個 WSDL 文檔即可形成這樣一個文檔。
清單 15:個案研究 4 單個文檔中完整的 WSDL 服務定義
<?xml version="1.0"?>
<definitions name="StockQuoteService"
targetNamespace="http://www.getquote.com/StockQuoteService"
xmlns:tns="http://www.getquote.com/StockQuoteService"
xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<documentation>
Service definition for a complete 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-stock-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:single-stock-quotes"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="StockQuoteService">
<documentation>Stock Quote Service</documentation>
<port name="SingleSymbolService"
binding="tns:SingleSymbolBinding">
<soap:address location="http://www.getquote.com/stockquoteservice"/>
</port>
</service>
</definitions>
|
發布 UDDI tModel
當 UDDI tModel 被發布時,它將包含對 WSDL 文檔(該文檔包含完整的服務描述)的引用。創建這個 tModel 使用的過程與為 WSDL 服務接口定義所定義的過程一樣。盡管 overviewURL 將包含對一個完整的 WSDL 文檔的引用,tModel 仍是只引用這個文檔中的綁定。這意味著 tModel 不引用 service 和 port 元素。
清單 16:個案研究 4 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
<name>http://www.getquote.com/StockQuoteService</name>
<description xml:lang="en">
Service definition for a complete stock quote service.
</description>
<overviewDoc>
<description xml:lang="en">
WSDL Service Interface Document
</description>
<overviewURL>
http://www.getquote.com/services/SQS.wsdl
</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>
|
發布 UDDI businessService
UDDI businessService 是根據完整的 WSDL 服務描述創建的,使用的過程與 WSDL 服務實現文檔所用的一樣。
清單 17:個案研究 4 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
<name>StockQuoteService</name>
<description xml:lang="en">
Stock Quote Service
</description>
<bindingTemplates>
<bindingTemplate bindingKey="" serviceKey="">
<accesssPoint URLType="http">
http://www.getquote.com/stockquoteservice
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo tModelKey="[tModel Key for Service Interface]">
<instanceDetails>
<overviewURL>
http://www.getquote.com/services/SQS.wsdl#SingleSymbolService
</overviewURL>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
</bindingTemplates>
<categoryBag>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</businessService>
|
個案研究 5:引用另一個服務接口的服務接口
服務接口提供者可以開發僅包含 types、message 和 portType 元素的服務接口。然后這個服務接口可被其它的服務接口提供者用來為服務接口指定特定綁定。只有包含這些綁定的服務接口才可被作為 UDDI tModel 發布。僅包含 types、message 和 portType 元素的 WSDL 服務接口無法被作為 UDDI tModel 發布。UDDI tModel 只可引用至少包含一個 binding 元素的 WSDL 服務接口。
帶有 messages 和 portTypes 的 WSDL 服務接口定義
服務接口提供者開發了僅包含 messages 和 portTypes 的服務接口。服務接口不必包含綁定規范。
清單 18:個案研究 5 帶有 messages 和 portType 的 WSDL 服務接口定義
<?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 service interface definition for a stock quote service
without any bindings.
</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>
</definitions>
|
帶有多個綁定(bindings)的 WSDL 服務接口定義
服務提供者可以實現僅包含 message 和 portType 元素的現有服務接口定義。這個實現會要求一個特定綁定,這個綁定由服務提供者指定。這個綁定規范被放在一個服務接口文檔中,該文檔還將包含對原始服務接口文檔的引用。
清單 19:個案研究 5 帶有多個綁定的 WSDL 服務接口定義
<?xml version="1.0"?>
<definitions name="StockQuoteService-binding"
targetNamespace="http://www.getquote.com/StockQuoteService-binding"
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>
Service interface binding definition for a stock quote service.
</documentation>
<import namespace="http://www.getquote.com/StockQuoteService-interface/"
location="http://www.getquote.com/SQS-interface.wsdl">
<binding name="SingleSymbolBinding"
type="interface: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>
|
發布帶有多個綁定的服務接口的 UDDI tModel
帶有多個綁定的服務接口的 tModel 可作為 tModel 被發布。這個 tModel 將只引用包含綁定定義的 WSDL 服務接口文檔。必須檢索這個文檔來確定包含服務接口定義其余內容的文檔。完整的服務接口定義是根據原始服務接口文檔中的 import 語句確定的。
清單 20包含一個 UDDI tModel,這個 UDDI tModel 是根據只包含綁定定義的 WSDL 服務接口定義創建的。
清單 20:個案研究 4 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
<name>http://www.getquote.com/StockQuoteService-binding</name>
<description xml:lang="en">
Service interface binding definition for a stock quote service.
</description>
<overviewDoc>
<description xml:lang="en">
WSDL Service Interface Document
</description>
<overviewURL>
http://www.getquote.com/services/SQS-binding.wsdl
</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>
|
WSDL 服務實現定義
WSDL 服務實現文檔包含一個 import 引用,它只引用包含綁定定義的 WSDL 服務接口文檔。對這個服務定義進行操作的 WSDL 工具或運行時環境必須能夠遵循完整的導入鏈。這個文檔將導入包含 binding 元素的 WSDL 文檔,然后它導入包含 types、message 和 portType 元素的 WSDL 文檔。這 3 個文檔全部結合在一起提供一個完整的 WSDL 服務定義。
清單 21:個案研究 5 WSDL 服務實現定義
<?xml version="1.0"?>
<definitions name="StockQuoteService"
targetNamespace="http://www.getquote.com/StockQuoteService"
xmlns:binding="http://www.getquote.com/StockQuoteService-binding"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<import namespace="http://www.getquote.com/StockQuoteService-binding"
location="http://www.getquote.com/wsdl/SQS-binding.wsdl"/>
<service name="StockQuoteService">
<documentation>Stock Quote Service</documentation>
<port name="SingleSymbolService"
binding="binding:SingleSymbolBinding">
<soap:address location="http://www.getquote.com/stockquoteservice"/>
</port>
</service>
</definitions>
|
發布 UDDI businessService
WSDL 服務實現定義是作為 UDDI businessService 被發布的。每個 tModel 都將被使用 tModelInstanceInfo
元素引用。兩個 tModel 都是引用,因此可使用任一個 tModel 執行搜索操作。
必須遍歷導入鏈來確定需要的 tModelInstanceInfo
的數目。對于這個個案研究,導入鏈中只有兩個服務接口文檔,所以將只在 bindingTemplate 中指定兩個 tModelInstanceInfo
元素。
第 1 個 tModelInstanceInfo
將包含對包含綁定定義的服務接口文檔的引用。這個 tModelInstanceInfo
還將包含一個將引用 WSDL 服務實現文檔的 overviewURL。
第 2 個 tModelInstanceInfo
元素將引用與包含 message 和 portType 元素的服務接口相關聯的 tModel。這個 tModelInstanceInfo
將不包含 overviewURL 元素。
清單 22:個案研究 5 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
<name>StockQuoteService</name>
<description xml:lang="en">
Stock Quote Service
</description>
<bindingTemplates>
<bindingTemplate bindingKey="" serviceKey="">
<accesssPoint URLType="http">
http://www.getquote.com/stockquoteservice
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo
tModelKey="[tModel Key for binding Service Interface]">
<instanceDetails>
<overviewURL>
http://www.getquote.com/services/SQS.wsdl#SingleSymbolService
</overviewURL>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
</bindingTemplates>
<categoryBag>
<keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384"
keyName="Stock market trading services"
keyValue="84121801"/>
</categoryBag>
</businessService>
|
總結
在本文中,我討論了幾個 WSDL 用法個案研究,它們展示了如何在 UDDI 注冊中心發布不同類型的 WSDL 服務描述。這些個案研究提供了基于 XML 的從 WSDL 到適當的 UDDI 數據實體的映射。這個系列的下一篇文章將展示如何使用 UDDI for Java API(UDDI4J)和“Java 工具箱 Web 服務描述語言”(Web Services Description Language for Java Toolkit(WSDL4J))通過編程在 UDDI 注冊中心發布 WSDL 服務描述。這兩個包都是開放源代碼的項目,可在 參考資料部分訪問。
參考資料