qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

          精通軟件性能測試與LoadRunner最佳實戰(zhàn) 連載十二

          13.13  Web Services協(xié)議腳本應(yīng)用

            13.13.1  Web Services簡介

            Web Service是基于網(wǎng)絡(luò)的、分布式的模塊化組件,它執(zhí)行特定的任務(wù),遵守具體的技術(shù)規(guī)范,這些規(guī)范使得Web Service能與其他兼容的組件進行互操作。Internet Inter-Orb Protocol(IIOP)都已經(jīng)發(fā)布了很長時間了,但是這些模型都依賴于特殊對象模型協(xié)議,而Web Services利用SOAP和XML對這些模型在通信方面作了進一步的擴展以消除特殊對象模型的障礙。Web Services主要利用HTTP和SOAP協(xié)議使商業(yè)數(shù)據(jù)在Web上傳輸,SOAP通過HTTP調(diào)用商業(yè)對象執(zhí)行遠程功能調(diào)用,Web用戶能夠使用SOAP和HTTP通過Web調(diào)用的方法來調(diào)用遠程對象。

            客戶根據(jù)WSDL描述文檔,會生成一個SOAP請求消息,請求會被嵌入在一個HTTP POST請求中,發(fā)送到Web服務(wù)器來。Web Services部署于Web服務(wù)器端,Web服務(wù)器把這些請求轉(zhuǎn)發(fā)給Web Services請求處理器。請求處理器解析收到的請求,調(diào)用Web Services,然后再生成相應(yīng)的SOAP應(yīng)答。Web服務(wù)器得到SOAP應(yīng)答后,會再通過HTTP應(yīng)答的方式把信息送回到客戶端。

            下面針對Web Services中的一些重要名詞進行講解。

            (1)UDDI,英文為“Universal Description, Discovery and Integration”,可譯為“通用描述、發(fā)現(xiàn)與集成服務(wù)”。UDDI是一個獨立于平臺的框架,用于通過使用Internet來描述服務(wù),發(fā)現(xiàn)企業(yè),并對企業(yè)服務(wù)進行集成。任何規(guī)模的行業(yè)或企業(yè)都能得益于UDDI,UDDI使用W3C和IETF*的因特網(wǎng)標準,比如XML、HTTP和DNS協(xié)議。在UDDI之前,還不存在一種Internet標準,可以供企業(yè)為它們的企業(yè)和伙伴提供有關(guān)其產(chǎn)品和服務(wù)的信息。也不存在一種方法,來集成到彼此的系統(tǒng)和進程中。那么UDDI有什么樣的用途呢?舉個例子來講,假如航空行業(yè)發(fā)布了一個用于航班預(yù)訂的UDDI標準,航空公司就可以把它們的服務(wù)注冊到一個UDDI目錄中。然后旅行社就能夠搜索這個UDDI目錄以找到航空公司預(yù)訂界面。當此界面被找到后,旅行社就能夠立即與此服務(wù)進行通信,這是由于它使用了一套定義良好的預(yù)訂界面。

            (2)WSDL英文為“Web Services Description Language”,可譯為網(wǎng)絡(luò)服務(wù)描述語言。它是一種使用XML編寫的文檔,可描述某個Web Service。它可規(guī)定服務(wù)的位置,以及此服務(wù)提供的操作(或方法)。WSDL文檔僅僅是一個簡單的XML文檔,它包含一系列描述某個Web Service的定義。

            以下WSDL文檔的簡化的片段是后續(xù)將會講到的,這里我們先拿出來分析一下:

          <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>
          <?xml version="1.0" encoding="utf-8"?>
          <definitions xmlns=http://schemas.xmlsoap.org/wsdl/
          xmlns:xs=http://www.w3.org/2001/XMLSchema name="IMyHelloservice"
          targetNamespace=http://tempuri.org/ xmlns:tns=http://tempuri.org/
          xmlns:soap=http://schemas.xmlsoap.org/wsdl/soap/
          xmlns:soapenc=http://schemas.xmlsoap.org/soap/encoding/
          xmlns:mime=http://schemas.xmlsoap.org/wsdl/mime/>
          <message name="Welcome0Request">
          <part name="name" type="xs:string" />
          </message>
          <message name="Welcome0Response">
          <part name="return" type="xs:string" />
          </message>
          <portType name="IMyHello">
          <operation name="Welcome">
          <input message="tns:Welcome0Request" />
          <output message="tns:Welcome0Response" />
          </operation>
          </portType>

          <binding name="IMyHellobinding" type="tns:IMyHello">
          <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
          <operation name="Welcome">
          <soap:operation soapAction="urn:MyHelloIntf-IMyHello#Welcome" style="rpc" />
          <input message="tns:Welcome0Request">
          <soap:body use="encoded" encodingStyle=http://schemas.xmlsoap.org/soap/encoding/
          namespace="urn:MyHelloIntf-IMyHello" />
          </input>
          <output message="tns:Welcome0Response">
          <soap:body use="encoded" encodingStyle=http://schemas.xmlsoap.org/soap/encoding/
          namespace="urn:MyHelloIntf-IMyHello" />
          </output>
          </operation>
          </binding>
          <service name="IMyHelloservice">
          <port name="IMyHelloPort" binding="tns:IMyHellobinding">
          <soap:address location=http://localhost:5678/soap/IMyHello />
          </port>
          </service>
          </definitions>

            我們可以將該WSDL 文檔分成三部分。

            第一部分:聲明部分內(nèi)容

          <xml version="1.0" encoding="utf-8"?>
          <definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
          xmlns:xs="http://www.w3.org/2001/XMLSchema" name="IMyHelloservice"
          targetNamespace="http://tempuri.org/" xmlns:tns="http://tempuri.org/"
          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
          xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
          xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">

            第二部分:


          <message name="Welcome0Request">
          <part name="name" type="xs:string" />
          </message>
          <message name="Welcome0Response">
          <part name="return" type="xs:string" />
          </message>
          <portType name="IMyHello">
          <operation name="Welcome">
          <input message="tns:Welcome0Request" />
          <output message="tns:Welcome0Response" />
          </operation>
          </portType>
          <binding name="IMyHellobinding" type="tns:IMyHello">
          <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
          <operation name="Welcome">
          <soap:operation soapAction="urn:MyHelloIntf-IMyHello#Welcome" style="rpc" />
          <input message="tns:Welcome0Request">
          <soap:body use="encoded" encodingStyle=http://schemas.xmlsoap.org/soap/encoding/
          namespace="urn:MyHelloIntf-IMyHello" />
          </input>
          <output message="tns:Welcome0Response">
          <soap:body use="encoded" encodingStyle=http://schemas.xmlsoap.org/soap/encoding/
          namespace="urn:MyHelloIntf-IMyHello" />
          </output>
          </operation>
          </binding>

           在這部分內(nèi)容中,<portType> 元素把 " IMyHello" 定義為某個端口的名稱,把 " Welcome " 定義為某個操作的名稱。操作 " Welcome " 擁有一個名為 " Welcome0Request " 的輸入消息,以及一個名為 " Welcome0Response " 的輸出消息。<message> 元素可定義每個消息的部件,以及相關(guān)聯(lián)的數(shù)據(jù)類型。從上面的文檔您不難發(fā)現(xiàn),其主要有以下元素的元素來描述某個web service ,參見表13-5。

          表13-5   WSDL 文檔結(jié)構(gòu)表

              

              

          <portType>

          Web Service 執(zhí)行的操作

          <message>

          Web Service 使用的消息

          <types>

          Web Service 使用的數(shù)據(jù)類型

          <binding>

          Web Service 使用的通信協(xié)議

            <portType> 元素是最重要的WSDL元素。它可描述一個 Web Service、可被執(zhí)行的操作,以及相關(guān)的消息。可以把<portType>元素比作傳統(tǒng)編程語言中的一個函數(shù)庫(或一個模塊、或一個類)、<message>元素定義一個操作的數(shù)據(jù)元素。每個消息均由一個或多個部件組成。可以把這些部件比作傳統(tǒng)編程語言中一個函數(shù)調(diào)用的參數(shù)、<types>元素定義Web Service使用的數(shù)據(jù)類型。為了最大程度的平臺中立性,WSDL使用XML Schema語法來定義數(shù)據(jù)類型、<binding>元素為每個端口定義消息格式和協(xié)議細節(jié)。binding元素的name屬性定義binding的名稱,而type屬性指向用于binding的端口,在這個例子中是“ImyHello”端口。

            soap:binding元素的style屬性可取值“rpc”或“document”。在這個例子中我們使用rpc、transport屬性定義了要使用的SOAP協(xié)議,在這個例子中我們使用HTTP。operation元素定義了每個端口提供的操作符,對于每個操作,相應(yīng)的SOAP行為都需要被定義。同時您必須對輸入和輸出進行編碼。在這個例子中我們使用了“encoded”。

            第三部分:

          <service name="IMyHelloservice">
          <port name="IMyHelloPort" binding="tns:IMyHellobinding">
          <soap:address location="http://localhost:5678/soap/IMyHello" />
          </port>
          </service>

            service是一套<port>元素。在一一對應(yīng)形式下,每個<port>元素都和一個location關(guān)聯(lián)。如果同一個<binding>有多個<port>元素與之關(guān)聯(lián),可以使用額外的URL地址作為替換。

            一個WSDL文檔中可以有多個<service>元素,而且多個<service>元素十分有用,其中之一就是可以根據(jù)目標URL來組織端口。這樣,我就可以方便地使用另一個<service>來重定向我的股市查詢申請。我的客戶端程序仍然工作,因為這種根據(jù)協(xié)議歸類的服務(wù)不隨服務(wù)而變化。多個<service>元素的另一個作用是根據(jù)特定的協(xié)議劃分端口。例如,我可以把所有的HTTP端口放在同一個<service>中,所有的SMTP端口放在另一個<service>里。

           后續(xù)內(nèi)容請從書籍獲得……

            (未完待續(xù))

          版權(quán)聲明:51Testing軟件測試網(wǎng)及相關(guān)內(nèi)容提供者擁有51testing.com內(nèi)容的全部版權(quán),未經(jīng)明確的書面許可,任何人或單位不得對本網(wǎng)站內(nèi)容復(fù)制、轉(zhuǎn)載或進行鏡像。51testing軟件測試網(wǎng)歡迎與業(yè)內(nèi)同行進行有益的合作和交流,如果有任何有關(guān)內(nèi)容方面的合作事宜,請聯(lián)系我們。

          相關(guān)鏈接:

          精通軟件性能測試與LoadRunner最佳實戰(zhàn) 連載十一


          posted on 2013-07-12 10:15 順其自然EVO 閱讀(170) 評論(0)  編輯  收藏 所屬分類: 測試學(xué)習(xí)專欄

          <2013年7月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 登封市| 武城县| 锡林浩特市| 德钦县| 鄂伦春自治旗| 突泉县| 循化| 蒲江县| 陆河县| 武陟县| 白银市| 德庆县| 清原| 阳信县| 安西县| 邹平县| 佛山市| 肥乡县| 金阳县| 定襄县| 渝北区| 仁怀市| 阿图什市| 焦作市| 农安县| 厦门市| 得荣县| 耒阳市| 逊克县| 瓦房店市| 铜山县| 榆社县| 襄垣县| 民乐县| 玉林市| 错那县| 平和县| 嘉黎县| 松阳县| 靖西县| 祁连县|