最后,我給出對應(yīng)本節(jié)描述的save_category元素的schema定義的schema圖示來結(jié)束本小節(jié)。
figure 1. soap api schema圖示
wsdl服務(wù)描述
對soap api消息完成schema建模之后,一方面這個數(shù)據(jù)模型可以由soap interface來使用,當(dāng)發(fā)生具體調(diào)用時可以使用這個數(shù)據(jù)模型來除了傳入的參數(shù)并生成傳出的參數(shù)。同時,利用這個數(shù)據(jù)模型,我們可以生成相應(yīng)的wsdl描述,從而將這個web服務(wù)的接口文檔發(fā)布給使用者,該接口文檔是具備被程序自動處理的能力的。
以下是wsdl文檔詳細(xì)的定義:(完整的wsdl文檔是: sagitta.wsdl)
<?xml version="1.0"?>
<definitions name="catalogservice"
targetnamespace="http://www.sagitta.com/wsdl/savecategory.wsdl"
xmlns:tns="http://www.sagitta.com/wsdl/savecategory.wsdl"
xmlns:myxs="http://www.sagitta.com/schema/"
xmlns:soap="http://www.w3.org/2001/06/soap-envelope"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<import namespace="http://www.sagitta.com/schema/" location=" http://www.sagitta.com/schema/save_category.xsd" />
這是wsdl文件的文件頭,其中的import元素指明在這個wsdl文件中,types系統(tǒng)是由http://www.sagitta.com/schema/save_category.xsd文件具體描述,在這里僅僅是將其導(dǎo)入。
<message name="save_category">
<part name="body" element="myxs:save_category"/>
</message>
<message name="categorylist">
<part name="body" element="myxs:categorylist"/>
</message>
這里定義了兩條消息:save_category消息,在前面的schema建模中已經(jīng)完整地創(chuàng)建了根元素的結(jié)構(gòu)定義。其中myxs是這里使用的命名空間(namespace),命名空間的具體定義在文件頭上出現(xiàn)。而categorylist將會對應(yīng)save_category消息的返回消息,在schema建模中沒有表現(xiàn),在這里我也僅列出一個元素名,相信大家在看了本文的前半部分以及本系列的前一篇文章之后,會很清楚如何來定義。
<porttype name="save_category_porttype">
<operation name="save_category_operation">
<input message="tns:save_category"/>
<output message="tns:categorylist"/>
</operation>
</porttype>
這部分定義了服務(wù)訪問點的調(diào)用模式的類型,表明這個入口類型是請求/響應(yīng)模式,請求消息是save_category,而響應(yīng)消息是categorylist。
<binding name="save_category_soapbinding" type=" save_category_porttype ">
<soap:binding transport=" http://www.w3.org/2001/06/soap-envelope/http">
<operation name="save_category_operation">
<soap:operation soapaction=" http://www.sagitta.com/catalog/">
<input>
<soap:body use="literal" namespace=" http://www.sagitta.com/schema/"
encodingstyle=" http://www.w3.org/2001/06/soap-encoding"/>
</input>
<output>
<soap:body use="literal" namespace=" http://www.sagitta.com/schema/"
encodingstyle=" http://www.w3.org/2001/06/soap-encoding"/>
</output>
</soap:operation>
</operation>
</soap:binding>
</binding>
這部分將服務(wù)訪問點的抽象定義與soap http綁定,描述如何通過soap/http來訪問按照前面描述的訪問入口點類型部署的訪問入口。其中規(guī)定了在具體soap調(diào)用時,應(yīng)當(dāng)使用的soapaction是"http://www.sagitta.com/catalog/",而請求/響應(yīng)消息的編碼風(fēng)格都應(yīng)當(dāng)采用soap規(guī)范默認(rèn)定義的編碼風(fēng)格" http://www.w3.org/2001/06/soap-encoding "。
<service name="catalogservice">
<documentation>online web service for catalog</documentation>
<port name="save_category_port" binding="tns:save_category_soapbinding">
<soap:address location="http://www.sagitta.com/catalog/"/>
</port>
</service>
</definitions>
這部分是具體的web服務(wù)的定義,在這個名為catalogservice的web服務(wù)中,提供了一個服務(wù)訪問入口(其實還有很多,不過在這里因為演示的原因,僅僅介紹了一個),訪問地址是"http://www.sagitta.com/catalog/",使用的消息模式是由前面的binding所定義的。
uddi服務(wù)發(fā)布
在前一節(jié)中,我們已經(jīng)通過使用wsdl這個工具將catalog service這個web服務(wù)進(jìn)行了結(jié)構(gòu)化地描述。為了使更多的潛在用戶能夠發(fā)現(xiàn)這個web服務(wù),同時也為了加強(qiáng)這個web服務(wù)的互操作能力和災(zāi)難恢復(fù)時的連接保持能力,我們需要使用uddi sdk將這個web服務(wù)注冊到uddi注冊中心中去。
假設(shè)我們之前已經(jīng)注冊了一個businessentity,叫做www.sagitta.com,一個在線服務(wù)提供商,這個businessentity的鍵值是"434554f4-6e17-1342-ea41-36e642531da1",那么我們要在這個businessentity下注冊一個businessservice,以用于描述前面的catalog service。同時需要成立的假設(shè)是我們也預(yù)先注冊了一個service type(tmodel),這個tmodel描述了我們這個需要發(fā)布的web服務(wù)的調(diào)用規(guī)范,具體內(nèi)容是前面我定義的這個wsdl文檔,在uddi中,注冊的是描述的鏈接。
businessservice注冊的soap消息如下,其中使用了microsoft的test.uddi.microsoft.com站點,因此authinfo中可以填入測試用的udditest。
<?xml version="1.0" encoding="utf-8"?>
<envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<body>
<save_service generic="1.0" xmlns="urn:uddi-org:api">
<authinfo>udditest</authinfo>
<businessservice businesskey="434554f4-6e17-1342-ea41-36e642531da1" servicekey="">
<name>categoryservice</name>
<description xml:lang="en">online web service for catalog</description>
<bindingtemplates>
<bindingtemplate bindingkey="" servicekey="">
<description xml:lang="en">categoryservice's bindingtemplate3</description>
<accesspoint urltype="http">http://www.sagitta.com/catalog/</accesspoint>
<tmodelinstancedetails>
<tmodelinstanceinfo tmodelkey="uuid:e31a569a-aeff-4468-ba4d-2bf22fe4acef">
<description xml:lang="en">sagitta web service type description</description>
<instancedetails>
<description xml:lang="en">sagitta web service type description</description>
<overviewdoc>
<description xml:lang="en">sagitta web service overview</description>
<overviewurl>http://www.sagitta.com/wsdl/savecategory.wsdl</overviewurl>
</overviewdoc>
</instancedetails>
</tmodelinstanceinfo>
</tmodelinstancedetails>
</bindingtemplate>
</bindingtemplates>
</businessservice>
</save_service>
</body>
</envelope>
通過上述的api調(diào)用,我們就已經(jīng)把這個服務(wù)注冊進(jìn)了uddi注冊中心,其中bindingtemplate的accesspoint是服務(wù)的入口,而overviewdoc中的overviewurl是wsdl文檔的訪問位置。
潛在的使用者可以通過查詢uddi注冊中心找到這個web服務(wù),通過overviewurl中保存的url找到服務(wù)的描述,然后通過accesspoint所指定的訪問地址來訪問這個服務(wù)。
當(dāng)發(fā)生緊急服務(wù)崩潰的時候,web服務(wù)可能被遷移到另一臺主機(jī)上,ip地址,甚至是訪問的url都可能有很大變化,此時原先的集成的連接將不再工作。但是由于uddi注冊的存在,我們可以通過自動化的程序手段來解決這個問題,使得類似的服務(wù)災(zāi)難恢復(fù)的過程非常迅速。
具體的流程一般是:
當(dāng)恢復(fù)的服務(wù)啟動后,自動去更新uddi注冊中心上的數(shù)據(jù),將訪問入口修改到新的url位置;
連入的客戶端系統(tǒng)當(dāng)發(fā)現(xiàn)無法訪問最終服務(wù)的時候,將會定期去查詢uddi注冊中心,看看新的bindingtemplate數(shù)據(jù)和本地緩存的有沒有差別,如果有的話,就下載到本地,重新建立服務(wù)綁定,完成服務(wù)連接的遷移。
總結(jié)
到這篇文章為止,如何架構(gòu)web service這個系列就將告一段落,在整個系列中,從為什么要有web服務(wù)開始,到什么是web服務(wù),web服務(wù)的開發(fā)工具,對web服務(wù)作了一個概念上的全面介紹。然后以一個具體實例來介紹web服務(wù)的構(gòu)建模式和各種web service "stack"技術(shù)的具體應(yīng)用。希望這個系列對大家理解和接受下一代的應(yīng)用包裝模式web服務(wù)有一個全面的幫助。
參考資料
web service 技術(shù)/評論網(wǎng)站
uddi-china.org, 以uddi為主的web服務(wù)技術(shù)網(wǎng)站。
webservices.org, web服務(wù)的綜合類技術(shù)網(wǎng)站。
ibm developerworks/web service zone, ibm的web服務(wù)技術(shù)資源中心
msdn online web services developer resources, microsoft的web服務(wù)的開發(fā)者資源網(wǎng)站
itpapers/web service, itpapers的web服務(wù)評論文章
解決b2b電子商務(wù)應(yīng)用交互和集成的interop stack系列技術(shù)標(biāo)準(zhǔn)規(guī)范
uddi執(zhí)行白皮書, uddi-china.org, uddi.org
uddi技術(shù)白皮書, uddi-china.org, uddi.org
uddi程序員api規(guī)范, uddi-china.org, uddi.org
uddi數(shù)據(jù)結(jié)構(gòu)參考, uddi-china.org, uddi.org
web service description language (wsdl) 1.0, ibm, 25 sep 2000
soap: simple object access protocol specification 1.1, ibm, microsoft, developmentor, 2000
xml schema part 0: primer , w3c, 2 may 2001
extensible markup language (xml) 1.0 (second edition), w3c, 6 oct 2000
作者簡介
柴曉路: 上海得易電子商務(wù)技術(shù)有限公司(dealeasy)首席系統(tǒng)架構(gòu)師、xml技術(shù)顧問。uddi-china.org藍(lán)色火焰工作室(blue blaze studio)成員。uddi advisor group成員,wsui working group成員。2000年獲復(fù)旦大學(xué)計算機(jī)科學(xué)碩士學(xué)位,曾在國際計算機(jī)科學(xué)學(xué)術(shù)會議(icsc)、亞太區(qū)xml技術(shù)研討會(xml asia/pacific'99)、中國xml技術(shù)研討會(北京)、計算機(jī)科學(xué)期刊等各類國際、國內(nèi)重要會議與期刊上發(fā)表論文多篇。專長于基于xml的系統(tǒng)集成和數(shù)據(jù)交換的技術(shù)研究,同時對數(shù)據(jù)庫、面向?qū)ο蠹夹g(shù)及cscw等技術(shù)比較擅長。
新聞熱點
疑難解答
圖片精選