qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          精通軟件性能測試與LoadRunner最佳實戰 連載十二

          13.13  Web Services協議腳本應用

            13.13.1  Web Services簡介

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

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

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

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

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

            以下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>
          <?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 文檔分成三部分。

            第一部分:聲明部分內容

          <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>

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

          表13-5   WSDL 文檔結構表

              

              

          <portType>

          Web Service 執行的操作

          <message>

          Web Service 使用的消息

          <types>

          Web Service 使用的數據類型

          <binding>

          Web Service 使用的通信協議

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

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

            第三部分:

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

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

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

           后續內容請從書籍獲得……

            (未完待續)

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

          相關鏈接:

          精通軟件性能測試與LoadRunner最佳實戰 連載十一


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

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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 瑞金市| 永寿县| 衡山县| 鄂伦春自治旗| 板桥市| 宜丰县| 永平县| 温州市| 韶关市| 芮城县| 崇仁县| 益阳市| 彭水| 基隆市| 玉屏| 台东县| 垣曲县| 高雄县| 班玛县| 务川| 台北市| 元谋县| 云霄县| 巴彦县| 青铜峡市| 皋兰县| 佛冈县| 奉化市| 措勤县| 东阳市| 都兰县| 正阳县| 且末县| 玉环县| 揭阳市| 德令哈市| 蛟河市| 上犹县| 新密市| 黑水县| 新和县|