<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-128  評(píng)論-55  文章-5  trackbacks-0
     

    理解 WSRF第1部分-使用 WS-ResourceProperties

     

    本教程是一個(gè)由 4 部分組成的系列文章中的第 1 部分,該系列介紹 WSRF 背后的概念。WSRF 是一組規(guī)范,提供一種標(biāo)準(zhǔn)方式,在 Web 服務(wù)應(yīng)用程序的本質(zhì)上“無狀態(tài)的”環(huán)境中與“有狀態(tài)”資源交互。這種有狀態(tài)資源實(shí)際上可以是任何東西,從數(shù)據(jù)庫到電子鼠標(biāo)都是有狀態(tài)資源。實(shí)際上,可以使用 WSRF 來處理任何可以通過改變其屬性來操縱的東西。

    WS-Resource 是一個(gè)有狀態(tài)資源(比如數(shù)據(jù)庫或硬盤)和它與之交互的 Web 服務(wù)的組合。本教程解釋了創(chuàng)建 WS-Resources、請(qǐng)求和更新用于定義 WS-Resource 狀態(tài)的屬性。我們將介紹以下內(nèi)容:

    1.       WSRF 規(guī)范的概述。

    2.       本系列教程中使用的系統(tǒng)的概述。

    3.       關(guān)于 WSDL 的基本信息。

    4.       關(guān)于的 WS-Addressing 的基本信息,WS-Addressing 用于定位 WS-Resource。

    5.       創(chuàng)建 WS-Resource。

    6.       獲得和設(shè)置 WS-Resource 屬性。

    注意,WSRF 作為一種規(guī)范,定義了描述這些操作的 WSDL 文件的結(jié)構(gòu)。該 WSDL 文件然后可以被任何語言的實(shí)現(xiàn)所使用。本教程描述 WSDL 文件的創(chuàng)建并展示產(chǎn)生的 SOAP 消息。

    一定要明白,WSRF 規(guī)范只定義應(yīng)該做什么,而不定義應(yīng)該如何做。這里描述的概念的實(shí)際實(shí)現(xiàn)留給了應(yīng)用程序去完成。在本系列的第 4 部分中,我們將使用 Globus Alliance 提供的 Core Java WSRF 類來討論該實(shí)現(xiàn)。

    在本系列中,我們將使用一系列圍繞地球的人造衛(wèi)星作為例子。我們將創(chuàng)建一個(gè) WS-Resource,它就代表這樣一個(gè)人造衛(wèi)星。然后我們將請(qǐng)求它的屬性以檢索它的數(shù)據(jù),更改它的屬性以將它發(fā)射到天空中,并更改它觀測(cè)的對(duì)象。

    l         網(wǎng)格計(jì)算簡(jiǎn)介

    首先,我們指出 WSRF 的應(yīng)用遠(yuǎn)遠(yuǎn)超出了網(wǎng)格,但是 WSRF 是在網(wǎng)格中開發(fā)的,所以網(wǎng)格是 WSRF 可以做什么的一個(gè)很好的例子。之后,將花點(diǎn)時(shí)間為那些不熟悉網(wǎng)格的人解釋一下網(wǎng)格是什么。

    數(shù)百萬的 Web 用戶已經(jīng)體驗(yàn)了網(wǎng)格計(jì)算,只是大多數(shù)人都沒有感覺到而已。1998 年,由于 NASA 發(fā)起了一個(gè)新計(jì)劃,使得 Search for Extraterrestrial Intelligence (SETI) 項(xiàng)目差點(diǎn)夭折,此時(shí)就創(chuàng)建了也許是最著名的網(wǎng)格計(jì)算項(xiàng)目。他們的 Aricebo 無線電望遠(yuǎn)鏡得到非常大量的數(shù)據(jù),但是沒有足夠的處理能力可以處理這些數(shù)據(jù)。為了解決這個(gè)問題,他們創(chuàng)建了一個(gè) screensaver,當(dāng)計(jì)算機(jī)不忙時(shí),它會(huì)從中央服務(wù)器請(qǐng)求一包數(shù)據(jù)并進(jìn)行分析,然后把結(jié)果發(fā)送回去。然后又請(qǐng)求一包新的數(shù)據(jù),并重復(fù)剛才的步驟。數(shù)百萬用戶下載了 screensaver 并參與該項(xiàng)目。

    大型網(wǎng)格應(yīng)用程序更加復(fù)雜,要處理的問題也更多,這些問題與身份驗(yàn)證、跨組織邊界的進(jìn)程間通信和高性能數(shù)據(jù)傳輸?shù)确矫嬗嘘P(guān)。盡管網(wǎng)格狂熱者可能不愿意聽到 SETI@Home 的情況,但是它確實(shí)提供了網(wǎng)格工作原理的一個(gè)很好的例子。它涉及以下步驟:

    工作被分成適合于在多個(gè)系統(tǒng)上處理的“單元”。該“工作”可以是計(jì)算、存儲(chǔ)或其他類型的處理。

    單元被分布到多個(gè)客戶機(jī)。這個(gè)步驟通過讓客戶機(jī)請(qǐng)求或“pull”工作,或者讓中央服務(wù)器將工作“push”給可用的客戶機(jī)來完成。

    總體進(jìn)展、需求和狀態(tài)由中央系統(tǒng)或系統(tǒng)組維護(hù)。

    當(dāng)前的網(wǎng)格應(yīng)用程序一般遵循這種模式,有一個(gè)中央系統(tǒng)與客戶機(jī)交互,這些客戶機(jī)位于那些一般在地理位置上與中央服務(wù)器分離的系統(tǒng)上。

    l         使用 Web 服務(wù):承諾和問題

    既然多個(gè)客戶機(jī)在不同的地方,那么 Web 服務(wù)應(yīng)該是網(wǎng)格計(jì)算順理成章的選擇。畢竟,它提供一種標(biāo)準(zhǔn)而容易的方法,以從一個(gè)系統(tǒng)到另一個(gè)系統(tǒng)獲得信息,而不用求助于特定于平臺(tái)或語言的方法,比如 CORBA、DCOM 或 Java-RMI。

    但是,原來并不是這樣的。早期的網(wǎng)格應(yīng)用程序使用其他更加不可移植的方法。但是為什么呢?

    也許最貼切的是體系結(jié)構(gòu)方面的原因。盡管網(wǎng)格應(yīng)用程序可以在很多機(jī)器上實(shí)現(xiàn),但它仍然是一個(gè)應(yīng)用程序,因此很難與本質(zhì)上是無狀態(tài)的體系結(jié)構(gòu)相協(xié)調(diào)。當(dāng)使用數(shù)據(jù)庫客戶機(jī)連接到一個(gè)數(shù)據(jù)庫時(shí),您就保持了連接,并且可以插入記錄,然后再查看插入的結(jié)果。另一個(gè)客戶查看表時(shí)不會(huì)看到該記錄,除非您提交了事務(wù),但是數(shù)據(jù)庫認(rèn)識(shí)您的會(huì)話,并知道是您。

    Web 服務(wù)的工作方式不是這樣的。利用 Web 服務(wù),您發(fā)出請(qǐng)求(比如插入一條記錄)并得到響應(yīng)(比如插入成功),然后斷開連接。沒有正在進(jìn)行的會(huì)話需要管理。例如 HTTP —— 在大多數(shù)情況下,Web 服務(wù)通過 HTTP 傳輸 —— 每個(gè)請(qǐng)求獨(dú)立于前一個(gè)請(qǐng)求,Web 服務(wù)沒有訪問或使用任何不是當(dāng)前輸入消息一部分的信息。

    WSRF 的目標(biāo)是通過創(chuàng)建“狀態(tài)”概念以及處理狀態(tài)的方法來解決該問題。

    l         有狀態(tài)資源

    那么到底什么是“狀態(tài)”,什么又是“有狀態(tài)”資源呢?

    有狀態(tài)資源是一些即使您不與之交互也存在的東西。例如數(shù)據(jù)庫,即使在您不查詢它的時(shí)候,它也存在。圍繞行星的人造衛(wèi)星即使在您不與之對(duì)話時(shí)也存在。甚至簡(jiǎn)單的計(jì)數(shù)器,在調(diào)用之間,或者每次調(diào)用它返回一個(gè) 1 時(shí),都必須存在。

    此外,一定要明白,狀態(tài)概念也包含屬性的思想。當(dāng)要求您把所借的東西以原狀態(tài)返還時(shí),涉及某些屬性的值,比如清潔度、修理要求、油罐中的汽油量,等等。有狀態(tài)資源與此類似,具有定義其狀態(tài)的屬性,并且這些屬性就是我們將與資源交互的方式,如 WS-Resource 的屬性 中所示。

    l         Web 服務(wù) + 有狀態(tài)資源 = WS-Resource

    根據(jù)規(guī)范可知,WS-Resource 是 Web 服務(wù)與它在其上起作用的有狀態(tài)資源的組合。但是這真正的含義是什么呢?

    讓我們從實(shí)際的角度來看這個(gè)問題。假設(shè)我們有一個(gè)系統(tǒng),涉及到管理一組人造衛(wèi)星。每個(gè)人造衛(wèi)星是一個(gè)有狀態(tài)資源,因?yàn)榧词乖谖覀儾慌c之對(duì)話時(shí)它也存在。我們還有一個(gè) Web 服務(wù),它提供人造衛(wèi)星功能,比如更改反向、檢索信息,或者甚至調(diào)整姿勢(shì)。

    通過將者二者組合起來,我們創(chuàng)建了一個(gè) WS-Resource。注意,并不需要一對(duì)一的對(duì)應(yīng)關(guān)系。例如,這個(gè) Web 服務(wù)可以與幾個(gè)不同的人造衛(wèi)星交互,從而創(chuàng)建幾個(gè)引用相同服務(wù)的不同 WS-Resources。另一方面,一個(gè)人造衛(wèi)星可以與幾個(gè)不同的服務(wù)(比如控制宇宙實(shí)驗(yàn)的服務(wù)和發(fā)射激光束的服務(wù))交互,從而創(chuàng)建幾個(gè)引用相同有狀態(tài)資源的不同 WS-Resources。

    為了使用 WS-Resource,必須了解它的屬性。

    l         WS-Resource 的屬性

    正如 有狀態(tài)資源 中所提到的,有狀態(tài)資源(以及 WS-Resource)具有各種與之相關(guān)的屬性。例如,人造衛(wèi)星可能具有以下屬性:

    latitude

    longitude

    altitude

    pitch

    yaw

    roll

    focalLength

    currentView

    在本例中,latitude、longitude 和 altitude 這前三個(gè)屬性指定人造衛(wèi)星的位置。其次,pitch、 yaw 和 roll 指定它的方位,或者說它看起來的方向。最后兩個(gè)屬性,focalLength 和 currentView,指定它離觀測(cè)點(diǎn)的距離以及它在這一點(diǎn)所看到的東西。

    這些屬性的值定義資源的狀態(tài)。更改屬性值,就更改了狀態(tài)。事實(shí)上,我們就是這樣來控制人造衛(wèi)星的。要更改它的位置,我們就改變它的一個(gè)位置屬性。要更改它的方位,我們就改變它的一個(gè)方位屬性。實(shí)際上,我們想要對(duì)該人造衛(wèi)星做任何事情(在這個(gè)非常有限的實(shí)現(xiàn)中),我們都只要改變這些屬性就可以了。

    但是如何來做到 這一點(diǎn)?

    l         進(jìn)入 WSRF

    好了,既然 WS-Resource 是有狀態(tài)資源和 Web 服務(wù)的組合,并且我們通過請(qǐng)求和設(shè)置它的屬性來操縱它,那么如何來做到這一點(diǎn)呢?

    有很多方法來做到這一點(diǎn),但是問題也正在于此。需要的是一種做出請(qǐng)求的標(biāo)準(zhǔn)方式,以獲取和設(shè)置各個(gè)屬性。

    進(jìn)入 WSRF。WSRF 實(shí)際上是一系列規(guī)范,用于定義標(biāo)準(zhǔn)的“消息模式”或方法,以請(qǐng)求屬性的值或者指定這些屬性應(yīng)該變更。實(shí)際上,WSRF 定義一些標(biāo)準(zhǔn)方法,以處理關(guān)于處理 WS-Resources 的各個(gè)方面,比如處理它們的屬性,從而將它們成組在一起,以達(dá)到諸如這樣的目的 —— 進(jìn)行身份驗(yàn)證,確保它們被及時(shí)地銷毀。

    WSRF 定義這些操作的方法是,指定它們應(yīng)該如何出現(xiàn)在 Web 服務(wù)描述語言(Web Services Description Language,WSDL)文件中。WSDL 文件定義 Web 服務(wù)會(huì)話兩端之間傳輸?shù)南?,所以通過定義 WSDL 文件,WSRF 定義了發(fā)生的任何交互的形式。

    當(dāng)我們說到“WSRF”時(shí),實(shí)際上是指幾個(gè)不同的規(guī)范:

    1.       WS-ResourceProperties (WSRF-RP)指定 ResourceProperties 在 WSDL 文件中被定義的形式。它還指定消息的形式,這些消息用于請(qǐng)求和接收屬性的值,還解釋了如何更改、添加和刪除 WS-Resource 的屬性。

    2.       WS-ResourceLifetime (WSRF-RL)談?wù)撨@樣一些狀態(tài),即 WS-Resource 需要過期了,或者在它不再需要了時(shí)應(yīng)該被顯式地銷毀。

    3.       WS-ServiceGroup (WSRF-SG)定義創(chuàng)建一組 Web 服務(wù)(比如可用服務(wù)的注冊(cè)表)的方法。

    4.       WS-Base Faults (WSRF-BF)定義一種標(biāo)準(zhǔn)的方法,用于指出基于 WSRF 的應(yīng)用程序中的錯(cuò)誤。

    您將注意到,沒有哪一個(gè)規(guī)范簡(jiǎn)單地描述了所有這一切應(yīng)該如何一起工作。這項(xiàng)工作(幾乎)是由 Modeling Stateful Resources with Web Services 白皮書完成的,該書解釋了一般的概念,并將它們聯(lián)系在一起。

    本教程除了介紹白皮書中的一些概念之外,還將討論 WS-ResourceProperties 規(guī)范。本系列的以后各期將討論其他的 WSRF 規(guī)范,以及 Web Services Notifications (WSN) 規(guī)范(整個(gè) WSRF 中都引用了這些規(guī)范)。

    l         什么是 WSDL,為什么我要關(guān)注它?

    在正式開始在 WSDL 文件中創(chuàng)建 WS-Resources 之前,我們首先花點(diǎn)時(shí)間來看一下 WSDL 文件的目的和結(jié)構(gòu)。這些描述就是在 WSDL 文件中。

    Web 服務(wù) —— 或者至少是與 WS-Resources 相關(guān)的 Web 服務(wù) —— 由 SOAP 消息組成。SOAP 消息具有一個(gè)標(biāo)準(zhǔn)的“信封”,其中包含一個(gè)“有效負(fù)載”。該有效負(fù)載是由服務(wù)器(在請(qǐng)求時(shí))和客戶機(jī)(在響應(yīng)時(shí))分析的數(shù)據(jù)??紤]下面這個(gè) SOAP 消息:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

        <SOAP-ENV:Header/>

        <SOAP-ENV:Body>

            <SetAltitudeRequest xmlns="http://example.com/satellite.xsd">

                <altitude>47700</altitude>

            </SetAltitudeRequest>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    它包含標(biāo)準(zhǔn)信封和有效負(fù)載,前者在 http://schemas.xmlsoap.org/soap/envelope/ 名稱空間(SOAP-ENV)中,后者在 http://example.com/satellite.xsd 名稱空間中。

    有效負(fù)載可以是任何東西,因此存在這樣一個(gè)問題:如何定義應(yīng)用程序期望看到什么,以及返回什么?因而有了 WSDL 文件的用武之地。最終,我們將使用一個(gè) WSDL 文件來定義 WS-Resource 所使用的“消息模式”,但是在本節(jié),我們只來看 WSDL 文件的各部分是如何組合在一起的。

    l         消息和類型

    我們首先定義一條我們將會(huì)發(fā)送的實(shí)際消息:

    <?xml version="1.0"?>

    <definitions name="Satellite"

        targetNamespace="http://example.com/satellite.wsdl"

        xmlns:tns="http://example.com/satellite.wsdl"

        xmlns:satTypes="http://example.com/satellite.xsd"

        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

        xmlns="http://schemas.xmlsoap.org/wsdl/">

        <types>

            <schema targetNamespace="http://example.com/satellite.xsd"

                  xmlns="http://www.w3.org/2000/10/XMLSchema">

               <element name="SetAltitudeRequest">

                  <complexType>

                      <all>

                          <element name="altitude" type="float"/>

                      </all>

                  </complexType>

               </element>

               <element name="SetAltitudeResponse">

                  <complexType>

                      <all>

                          <element name="result" type="string"/>

                      </all>

                  </complexType>

               </element>

           </schema>

        </types>

        <message name="SetAltitudeInput">

            <part name="body" element="satTypes:SetAltitudeRequest"/>

        </message>

        <message name="SetAltitudeOutput">

            <part name="body" element="satTypes:SetAltitudeResponse"/>

        </message>

    </definitions>

    從底部開始,我們定義了兩種類型的消息。第一種是 SetAltitudeInput,這是我們將發(fā)送給服務(wù)器作為輸入的消息。它是您在什么是 WSDL,為什么我要關(guān)注它? 中看到的 SOAP 消息中的消息。第二種消息是 SetAltitudeOutput,這是服務(wù)器發(fā)送給客戶機(jī)的響應(yīng)。兩種消息都指定一個(gè)元素,消息體將放在該元素中。

    這些元素的實(shí)際定義位于文件頂部的模式(schema)中。例如,SetAltitudeInput 消息包含一個(gè) SetAltitudeRequest 元素,該元素自己又包含一個(gè) altitude 元素,后面這個(gè)元素的內(nèi)容必須是一個(gè) float。

    接下來,我們將組合這些消息,以創(chuàng)建服務(wù)器執(zhí)行的一個(gè)操作。

    l         端口類型和操作

    既然知道了我們將要發(fā)送的消息是什么,現(xiàn)在就需要指定它們將要完成的角色。要做到這一點(diǎn),我們將創(chuàng)建一個(gè) portType 及其相關(guān)的 operation:

    ...

        <message name="SetAltitudeInput">

            <part name="body" element="satTypes:SetAltitudeRequest"/>

        </message>

        <message name="SetAltitudeOutput">

            <part name="body" element="satTypes:SetAltitudeResponse"/>

        </message>

        <portType name="AltitudePortType">

            <operation name="SetAltitude">

               <input message="tns:SetAltitudeInput"

                      wsa:Action="http://example.com/SetAltitude" />

               <output message="tns:SetAltitudeOutput"

                      wsa:Action="http://example.com/SetAltitudeResponse" />

            </operation>

        </portType>

    </definitions>

    這里,我們定義了一個(gè) portType 叫做 AltitudePortType,以及它的一個(gè) operation 叫做 SetAltitude。我們實(shí)際上可以在該 portType 中定義任意數(shù)量的操作,但是現(xiàn)在我們是為了保持簡(jiǎn)單。SetAltitude 操作指定一個(gè) input 消息 SetAltitudeInput 和一個(gè) output 消息 SetAltitudeOutput。(下一節(jié)我們將處理 wsa:Action 屬性。此外,請(qǐng)注意名稱空間信息。)

    您也可以指定一個(gè) fault 消息在有問題時(shí)發(fā)送,在本教程系列的后面將會(huì)介紹這一點(diǎn),但是現(xiàn)在還是保持簡(jiǎn)單。

    l         服務(wù)和綁定

    至此,我們已經(jīng)使用 portType 定義了可以做什么 事情,但是沒有定義如何 做。要完成這個(gè)過程,我們需要?jiǎng)?chuàng)建一個(gè)描述如何做的 binding,并將它附加到實(shí)際的 service:

    ...

        <portType name="AltitudePortType">

            <operation name="SetAltitude">

               <input message="tns:SetAltitudeInput"

                      wsa:Action="http://example.com/SetAltitude" />

               <output message="tns:SetAltitudeOutput"

                      wsa:Action="http://example.com/SetAltitudeResponse" />

            </operation>

        </portType>

        <binding name="AltitudeSoapBinding" type="tns:AltitudePortType">

            <soap:binding style="document"

                      transport="http://schemas.xmlsoap.org/soap/http"/>

            <operation name="SetAltitude">

               <input>

                   <soap:body use="literal"/>

               </input>

               <output>

                   <soap:body use="literal"/>

               </output>

            </operation>

        </binding>

        <service name="SatelliteService">

            <port name="AltitudePort" binding="tns:AltitudeSoapBinding">

                <soap:address location="http://example.com/satellite"/>

            </port>

        </service>

    </definitions>

    我們還是從底部開始,先看 service 元素。一個(gè) WSDL 文件可以定義多個(gè)服務(wù)。例如,您可能有用于不同目的的不同服務(wù),或者在不同位置有具有相同目的的不同服務(wù),或者具有不同綁定的不同服務(wù),比如一個(gè)用于 SOAP 的服務(wù)和一個(gè)用于 SMTP 的服務(wù)。

    在本例中,我們將利用一個(gè)端口 AltitudePort 來定義一個(gè)服務(wù) SatelliteService。但是我們知道關(guān)于該端口的哪些情況呢?哦,我們知道 SOAP 請(qǐng)求應(yīng)該發(fā)送到 http://example.com/satellite。我們還知道,為了獲得關(guān)于如何發(fā)送消息的更多信息,應(yīng)該檢查 AltitudeSoapBinding。

    AltitudeSoapBinding 指定它是 AltitudePortType 的一個(gè)實(shí)現(xiàn),所以我們知道發(fā)送什么消息。binding 本身指定每個(gè)操作中的消息是如何格式化的。在本例中,我們使用“document/literal”樣式,這意味著我們只是將定義好的元素拖放到 Body 中。

    我們知道了消息將發(fā)送到哪里,如何格式化這些消息,以及這些消息應(yīng)該是什么。到 創(chuàng)建 WS-Resource 一節(jié),我們將介紹如何創(chuàng)建 WSRF 定義的特定消息,但是首先我們需要了解一下 WS-Addressing。

    l         什么是 WS-Addressing,為什么我要關(guān)注它?

    以前,很容易指定 Web 服務(wù)的地址。所有您真正需要的就是 URL,所有其他信息都包含在 SoapAction 頭部或消息本身中。現(xiàn)在,Web 服務(wù)應(yīng)用程序變得越來越復(fù)雜,并不總是那么簡(jiǎn)單。您若想要讓應(yīng)答發(fā)送到除最初的請(qǐng)求者之外的其他地方,或者需要其他信息(比如會(huì)話標(biāo)識(shí)符)來定義實(shí)際的“位置”,那該怎么辦?

    或者您只是需要附加到 Web 服務(wù)的一個(gè)特定實(shí)例,那該怎么辦?我們?cè)?WS-Resources 的情況中將會(huì)遇到這個(gè)問題,所以我們需要一種處理它的方式。

    WS-Addressing 提供一種方式來指定關(guān)于位置的信息,而不只是一個(gè)統(tǒng)一資源標(biāo)識(shí)符(Universal Resource Identifier,URI)或 URL。實(shí)際上,在我們的例子中,它提供一種標(biāo)準(zhǔn)的方式,將大量的信息添加到 SOAP 消息。我們來構(gòu)造一個(gè) SOAP 消息,比如:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

    xmlns:wsa="http://www.w3.org/2005/02/addressing"

    xmlns:sat="http://example.org/satelliteSystem">

        <SOAP-ENV:Header>

          <wsa:To SOAP-ENV:mustUnderstand="1">http://example.com/satellite</wsa:To>

          <wsa:Action>http://example.com/SetAltitude</wsa:Action>

          <sat:SatelliteId>SAT9928</sat:SatelliteId>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

            <SetAltitudeRequest xmlns="http://example.com/satellite.xsd">

                <altitude>47700</altitude>

            </SetAltitudeRequest>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    在實(shí)際的 SOAP 消息中具有該信息似乎并不重要,但是請(qǐng)記住,消息可能會(huì)傳輸通過多個(gè)系統(tǒng),甚至需要多次傳輸才能到達(dá)最終目的地。

    要指定該信息,我們需要?jiǎng)?chuàng)建一個(gè) EndpointReference。

    WS-Addressing 引入了 EndpointReference 概念。EndpointReference 是一種方式,用于指定讓消息到達(dá)適當(dāng)?shù)奈恢貌в羞m當(dāng)?shù)南嚓P(guān)信息所需的信息。例如,我們?cè)谇耙黄林兄付ǖ南⒌?EndpointReference 應(yīng)該是:

    <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/02/addressing"

    xmlns:sat="http://example.org/satelliteSystem">

        <wsa:Address>http://example.com/satellite</wsa:Address>

        <wsa:ReferenceProperties>

             <sat:SatelliteId>SAT9928</sat:SatelliteId>

        </wsa:ReferenceProperties>

    </wsa:EndpointReference>

    理解 EndpointReference 和 SOAP 消息之間的關(guān)系很重要,因?yàn)?EndpointReference 就是我們指定特定 WS-Resource 的位置的方式。例如,當(dāng)我們請(qǐng)求創(chuàng)建新的 WS-Resource 時(shí),響應(yīng)將包含一個(gè)指向它的 EndpointReference。

    l         什么是 WS-Resource?

    至此,您應(yīng)該在概念上對(duì)什么是 WS-Resource 有了很好的理解,并且應(yīng)該對(duì) WSDL 和 WS-Addressing 有了很好的基本了解。現(xiàn)在開始實(shí)際地創(chuàng)建和使用 WS-Resources。

    我們首先來定義 WS-Resource 到底真正是什么。在我們的人造衛(wèi)星例子中,我們可以具有幾種類型的 WS-Resources,比如:

    一個(gè)服務(wù),用于設(shè)置或檢索特定人造衛(wèi)星的高度。

    一個(gè)服務(wù),用于設(shè)置或檢索特定人造衛(wèi)星的位置或方位。

    一個(gè)服務(wù),用于提供對(duì)一個(gè)進(jìn)程的訪問,該進(jìn)程計(jì)數(shù)特定人造衛(wèi)星觀測(cè)到的恒星。

    關(guān)于該列表有兩件事情一定要注意:即所有三個(gè) WS-Resources 都可以引用相同的人造衛(wèi)星,還有,WS-Resource 是由服務(wù)和有狀態(tài)資源(在本例中是人造衛(wèi)星)的組合定義的,而不是由它可以執(zhí)行的操作數(shù)量定義的。

    現(xiàn)在,我們可以說 WS-Resource 是 Web 服務(wù)和有狀態(tài)資源的組合,但是我們?nèi)绾卧趹?yīng)用程序中表示這個(gè)有狀態(tài)資源呢?答案就在它的 ResouceProperties 中。正如 有狀態(tài)資源 中提到的,對(duì)象的狀態(tài)可以由它的各種屬性的值來決定。因?yàn)槲覀冋嬲信d趣的就是對(duì)象的狀態(tài),所以我們可以把有狀態(tài)資源表示為一個(gè)展示其屬性的 XML 文檔。該文檔叫做資源屬性文檔。在我們的人造衛(wèi)星例子中,它可能是具有以下代碼行的文檔:

    <satProp:GenericSatelliteProperties  xmlns:satProp="http://example.com/satellite">

       <satProp:latitude>30.3</satProp:latitude>

       <satProp:longitude>223.2</satProp:latitude>

       <satProp:altitude>47700</satProp:altitude>

       <satProp:pitch>49</satProp:pitch>

       <satProp:yaw>0</satProp:yaw>

       <satProp:roll>32</satProp:roll>

       <satProp:focalLength>21999992</satProp:focalLength>

       <satProp:currentView>

            http://example.com/satellite/2239992333.zip

       </satProp:currentView>

    </satProp:GenericSatelliteProperties>

    狀態(tài)的更改需要一個(gè)或多個(gè)這些屬性的更改,反之亦然。

    就像可以通過添加成員或方法來擴(kuò)展類一樣,我么可以通過添加屬性來擴(kuò)展 WS-Resource。例如,考慮這樣一種情形,我們具有一個(gè)人造衛(wèi)星,它也充當(dāng)恒星計(jì)數(shù)器。除了有狀態(tài)資源的一般屬性之外,我們可能還有一個(gè) currentCount 屬性:

    <satProp:GenericSatelliteProperties

           xmlns:satProp="http://example.com/satellite"

           xmlns:counterProp="http://example.com/satellite/CounterSatelliteProperties">

       <satProp:latitude>30.3</satProp:latitude>

       <satProp:longitude>223.2</satProp:latitude>

       <satProp:altitude>47700</satProp:altitude>

       <satProp:pitch>49</satProp:pitch>

       <satProp:yaw>0</satProp:yaw>

       <satProp:roll>32</satProp:roll>

       <satProp:focalLength>21999992</satProp:focalLength>

       <satProp:currentView>

            http://example.com/satellite/2239992333.zip

       </satProp:currentView>

       <counterProp:currentCount>92828</counterProp:currentCount>

    </satProp:GenericSatelliteProperties>

    注意新信息是在一個(gè)獨(dú)立的名稱空間中。

    l         合并 WS- 和 Resource:WSDL 文件

    至此,我們已經(jīng)創(chuàng)建了有狀態(tài)資源(人造衛(wèi)星)的表示,但是要真正地創(chuàng)建 WS-Resource,我們還必須使用 WSDL 文件將它綁定到服務(wù)。

    我們首先來看一個(gè)基本的 WSDL 文件:

    <?xml version="1.0" encoding="UTF-8"?>

    <definitions name="Satellite"

        targetNamespace="http://example.com/satellite"

        xmlns="http://schemas.xmlsoap.org/wsdl/"

        xmlns:tns="http://example.com/satellite"

        xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"

        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

        xmlns:wsrp=

    "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"

        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

            <wsdl:import namespace=

    "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"

           location="WS-ResourceProperties.wsdl" />

            <types>

              <xsd:schema targetNamespace="http://example.com/satellite"

                          xmlns:xsd="http://www.w3.org/2001/XMLSchema">

                            <xsd:import namespace=

     "http://schemas.xmlsoap.org/ws/2004/03/addressing"

                               schemaLocation="WS-Addressing.xsd" />

              </xsd:schema>

            </types>

    </definitions>

    該文件現(xiàn)在還很空,但是請(qǐng)注意,為了能夠工作,還需要導(dǎo)入兩個(gè)文件。WS-ResourceProperties.wsdl 和 WS-Addressing.xsd 文件的典型版本可能會(huì)引用您還沒創(chuàng)建在機(jī)器上的目錄,所以為了簡(jiǎn)單起見,您可以從教程參考資料 下載簡(jiǎn)化的版本。

    既然有了框架,現(xiàn)在我們就來填充它吧。

    首先,我們將實(shí)際的有狀態(tài)資源添加到文件,并將之與 Web 服務(wù)關(guān)聯(lián):

    <?xml version="1.0" encoding="UTF-8"?>

    <definitions name="Satellite"

        targetNamespace="http://example.com/satellite"

        xmlns="http://schemas.xmlsoap.org/wsdl/"

        xmlns:tns="http://example.com/satellite"

        xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"

        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

        xmlns:wsrp=

    "http://docs.oasis-open.org/wsrf/2004/06/wsrf-

    WS-ResourceProperties-1.2-draft-01.xsd"

        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

            <wsdl:import namespace=

    "http://docs.oasis-open.org/wsrf/2004/06/wsrf-

    WS-ResourceProperties-1.2-draft-01.wsdl"

              location="WS-ResourceProperties.wsdl" />

          <types>

          <xsd:schema targetNamespace="http://example.com/satellite"

              xmlns:xsd="http://www.w3.org/2001/XMLSchema">

         

              <xsd:import namespace=

                      "http://schemas.xmlsoap.org/ws/2004/03/addressing"

                      schemaLocation="WS-Addressing.xsd" />

               

              <xsd:element name="latitude" type="xsd:float" />

              <xsd:element name="longitude" type="xsd:float" />

              <xsd:element name="altitude" type="xsd:float" />

              <xsd:element name="pitch" type="xsd:float" />

              <xsd:element name="yaw" type="xsd:float" />

              <xsd:element name="roll" type="xsd:float" />

              <xsd:element name="focalLength" type="xsd:float" />

              <xsd:element name="currentView" type="xsd:string" />

               

              <xsd:element name="GenericSatelliteProperties">

                <xsd:complexType>

                   <xsd:sequence>

                     <xsd:element ref="latitude" minOccurs="1"

                     maxOccurs="1"/>

                     <xsd:element ref="longitude" minOccurs="1"

                     maxOccurs="1"/>

                     <xsd:element ref="altitude" minOccurs="1"

                     maxOccurs="1"/>

                     <xsd:element ref="pitch" minOccurs="1"

                     maxOccurs="1"/>

                     <xsd:element ref="yaw" minOccurs="1"

                     maxOccurs="1"/>

                     <xsd:element ref="roll" minOccurs="1"

                     maxOccurs="1"/>

                    <xsd:element ref="focalLength" minOccurs="1"

                     maxOccurs="1"/>

                     <xsd:element ref="currentView" minOccurs="1"

                     maxOccurs="1"/>

                   </xsd:sequence>

                </xsd:complexType>

              </xsd:element>             

               

          </xsd:schema>

           

        </types>

        <portType name="SatellitePortType"

                wsrp:ResourceProperties=

                "tns:GenericSatelliteProperties">

        </portType>

       

        <binding name="SatelliteSoapBinding"

        type="tns:SatellitePortType">

          <soap:binding style="document"

          transport="http://schemas.xmlsoap.org/soap/http"/>

        </binding>

       

        <service name="SatelliteService">

            <port name="SatellitePort"

            binding="tns:SatelliteSoapBinding">

                <soap:address location=

                "http://example.com/satellite"/>

            </port>

        </service>

    </definitions>

    我們首先是添加 Web 服務(wù)的基礎(chǔ)、實(shí)際的 service 元素和將之與 portType 關(guān)聯(lián)的 binding。portType 本身還沒有任何操作,但是重要的部分是 wsrp:ResourceProperties 屬性。該屬性指定,Web 服務(wù)執(zhí)行的任何操作都是在一個(gè)特定類型的有狀態(tài)資源上執(zhí)行的,如 GenericSatelliteProperties 元素所定義的。GenericSatelliteProperties 元素定義在 schema 中。該有狀態(tài)資源和該 Web 服務(wù)的組合就是 WS-Resource。

    注意,規(guī)范中指出,在創(chuàng)建資源屬性文檔(比如本例中的 GenericSatelliteProperties)時(shí),必須 使用這里展示的樣式,即初始元素是定義和引用的,而不是內(nèi)聯(lián)地定義的。

    現(xiàn)在我們向 WSDL 文件添加一些實(shí)際的操作,看它是如何工作的。

    l         請(qǐng)求新的人造衛(wèi)星

    當(dāng)然,該練習(xí)的整個(gè)目的是真正對(duì) WS-Resource 做一些事情,所以我們要做的第一件事情是,創(chuàng)建對(duì)實(shí)際 WS-Resource 實(shí)例的一個(gè)引用:

    ...

        <types>

           <xsd:schema targetNamespace="http://example.com/satellite"

               xmlns:xsd="http://www.w3.org/2001/XMLSchema">

               

                <xsd:import namespace=

                   "http://schemas.xmlsoap.org/ws/2004/03/addressing"

                      schemaLocation="WS-Addressing.xsd" />

               

              <xsd:element name="createSatellite">

                  <xsd:complexType/>

              </xsd:element>

               

              <xsd:element name="createSatelliteResponse">

                 <xsd:complexType>

                     <xsd:sequence>

                         <xsd:element ref="wsa:EndpointReference"/>

                      </xsd:sequence>

                  </xsd:complexType>

              </xsd:element>

               

              <xsd:element name="GenericSatelliteProperties">

                   ...

              </xsd:element>           

               

            </xsd:schema>

           

        </types>

        <message name="CreateSatelliteRequest">

          <part name="request" element="tns:createSatellite"/>

        </message>

       

        <message name="CreateSatelliteResponse">

         <part name="response" element=

         "tns:createSatelliteResponse"/>

        </message>

       

        <portType name="SatellitePortType"

          wsrp:ResourceProperties=

          "tns:GenericSatelliteProperties">

          <operation name="createSatellite">

              <input message="tns:CreateSatelliteRequest"

                   wsa:Action=

                   "http://example.com/CreateSatellite" />

               <output message="tns:CreateSatelliteResponse"

                  wsa:Action=

                  "http://example.com/CreateSatelliteResponse" />

            </operation>

        </portType>

       

       <binding name="SatelliteSoapBinding" type=

       "tns:SatellitePortType">

        <soap:binding style="document" transport=

        "http://schemas.xmlsoap.org/soap/http"/>

          <operation name="createSatellite">

              <input>

                  <soap:body use="literal"/>

               </input>

               <output>

                  <soap:body use="literal"/>

               </output>

         </operation>

       </binding>

       

       <service name="SatelliteService">

          <port name="SatellitePort" binding=

          "tns:SatelliteSoapBinding">

              <soap:address location=

              "http://example.com/satellite"/>

           </port>

       </service>

    </definitions>

    乍一看,這與我們?cè)?需要了解的 WSDL 知識(shí) 中創(chuàng)建的 WSDL 文件沒有太大的區(qū)別。我們具有一個(gè)指向 binding 的 service,binding 解釋如何實(shí)現(xiàn) portType。portType 定義一個(gè)操作,即 createSatellite,該操作使用一個(gè) input 和一個(gè) output 消息。這兩個(gè)消息定義在 schema 中。

    這個(gè)文件有一點(diǎn)稍微與最初的文件不同:不是返回一個(gè)簡(jiǎn)單的值,服務(wù)是返回一個(gè)指向新創(chuàng)建的 WS-Resource 的 EndpointReference。我們來看這在 SOAP 消息中是如何實(shí)現(xiàn)的。

    l         SOAP 請(qǐng)求

    關(guān)于創(chuàng)建 WS-Resource 的實(shí)際 SOAP 請(qǐng)求是非常簡(jiǎn)單的:

    <SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

        <SOAP-ENV:Header/>

        <SOAP-ENV:Body>

            <createSatellite xmlns="http://example.com/satellite"/>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    我們還沒有實(shí)際的對(duì)象,所以該請(qǐng)求到達(dá) WSDL 文件中列出的 URI,并且我們將該請(qǐng)求定義為一個(gè)簡(jiǎn)單的 createSatellite 元素。

    響應(yīng)要稍微有意思一些。

    l         SOAP 響應(yīng)

    一旦您發(fā)送針對(duì)新人造衛(wèi)星的請(qǐng)求,服務(wù)器就創(chuàng)建一個(gè)對(duì)新 WS-Resource 的引用,并以 EndpointReference 形式將它返回:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

        <SOAP-ENV:Header/>

        <SOAP-ENV:Body>

           <wsa:EndpointReference

           xmlns:wsa="http://www.w3.org/2005/02/addressing"

                 xmlns:sat="http://example.org/satelliteSystem">

               <wsa:Address>http://example.com/satellite</wsa:Address>

               <wsa:ReferenceProperties>

                   <sat:SatelliteId>SAT9928</sat:SatelliteId>

               </wsa:ReferenceProperties>

           </wsa:EndpointReference>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    注意,EndpointReference 的 Address 元素指向我們?cè)?WSDL 文件中列出的同一 URI,所以信息仍然到達(dá)相同的地方,只是量的增多。

    現(xiàn)在我們應(yīng)該注意,這不是一個(gè)普通的端點(diǎn)引用。 ReferenceProperties 元素展示一個(gè)標(biāo)識(shí)符,該標(biāo)識(shí)符最終將用于識(shí)別 WS-Resource,所以這實(shí)際上是一個(gè) WS-Resource 限定的端點(diǎn)引用。正如您馬上就會(huì)看到的,我們可以使用該信息來對(duì) WS-Resource 做出后續(xù)調(diào)用。

    l         我們想要完成什么?

    好的,已經(jīng)創(chuàng)建了 WS-Resource,那么我們可以對(duì)它做什么呢?

    實(shí)際上,可以通過調(diào)整它的屬性來做任何事情。例如,可以通過更改 altitude 屬性來改變?nèi)嗽煨l(wèi)星軌道的大小。不,只是更改值并不能移動(dòng)人造衛(wèi)星;人造衛(wèi)星的實(shí)際移動(dòng)是由 Web 服務(wù)背后的應(yīng)用程序決定的。但是這是 WS-Resources 所真正關(guān)心的:創(chuàng)建一種方式,以便通過更改屬性來操縱對(duì)象。規(guī)范只是指出了如何將這些更改告訴 Web 服務(wù)。它不關(guān)心應(yīng)用程序是如何真正操縱對(duì)象的,我們也不關(guān)心。

    但是在真正開始更改屬性之前,我們先來看看屬性。在本節(jié)中,首先來看我們?cè)?創(chuàng)建 WS-Resource 中創(chuàng)建的人造衛(wèi)星 WS-Resource 的 altitude 屬性。然后將講述一次性請(qǐng)求所有的 orientation 值。然后再介紹使用 XPath 來查詢多個(gè)值。

    l         請(qǐng)求屬性

    請(qǐng)求屬性的值是構(gòu)造適當(dāng) SOAP 消息過程中的一個(gè)簡(jiǎn)單過程。例如,假設(shè)我們想要請(qǐng)求 altitude 屬性的值?;镜?SOAP 消息可能看起來像下面這樣:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

        xmlns:wsrp=

    "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-

    ResourceProperties-1.2-draft-01.xsd">

     <SOAP-ENV:Header>...</SOAP-ENV:Header>

     <SOAP-ENV:Body>

         <wsrp:GetResourceProperty xmlns:satProp=

         "http://example.com/satellite">

            satProp:altitude

         </wsrp:GetResourceProperty>

     </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    wsrp:GetResourceProperty 元素是 WS-ResourceProperties 規(guī)范的一部分。我們甚至不必在 WSDL 文件中定義它。它給我們這樣一個(gè)地方,可以指定我們想要獲得值的屬性。

    但是,SOAP 消息還沒有真正完成。是的,它是一個(gè) SOAP 消息,但是如果我們像這樣把它發(fā)送給 Web 服務(wù),服務(wù)將不知道我們引用的是哪個(gè) WS-Resource。接下來我們將關(guān)心這個(gè)問題。

    l         完全的 SOAP 請(qǐng)求

    在前一屏,即 請(qǐng)求屬性 中,我們創(chuàng)建了一個(gè) SOAP 消息,它指定了我們想要檢索的屬性,但是為哪個(gè) WS-Resource 創(chuàng)建的呢?

    當(dāng)創(chuàng)建人造衛(wèi)星時(shí),Web 服務(wù)返回一個(gè)指向新創(chuàng)建的 WS-Resource 的端點(diǎn)引用。我們可以將該信息添加到 SOAP 消息的 Header,像下面這樣:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

           xmlns:sat="http://example.org/satelliteSystem"

           xmlns:wsa="http://www.w3.org/2005/02/addressing"

           xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-

           WS-ResourceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

    http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceProperties/GetResourceProperty

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/satellite

           </wsa:To>

           <sat:SatelliteId>SAT9928</sat:SatelliteId>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:GetResourceProperty

           xmlns:satProp="http://example.com/satellite">

              satProp:altitude

           </wsrp:GetResourceProperty>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    wsa:Action 元素不是初始端點(diǎn)引用的一部分;它隨我們想要做的事情而變化。在本例中,我們使用 GetResourceProperty 操作。wsa:To 元素從端點(diǎn)引用中的 wsa:Address 獲得值,而任何 wsa:ReferenceProperty 值都直接包含在 Header 中。

    您會(huì)注意到,我們沒有討論 SatelliteId 值。這是故意的。包含在端點(diǎn)引用中的任何用于識(shí)別特定 WS-Resource 的信息都必須被應(yīng)用程序忽略,只是在發(fā)送消息時(shí)要傳送它。根據(jù)規(guī)范,即使嘗試去解釋值也認(rèn)為是不適當(dāng)?shù)?。這意味著被傳輸為一個(gè)“黑盒”,導(dǎo)致一種未經(jīng)檢查的生活。

    l         接收 ResourceProperty

    一旦請(qǐng)求屬性,就需要獲得返回值,并且 WS-ResourceProperties 規(guī)范也定義了這種消息的形式。在我們的例子中,我們將接收這樣一個(gè)消息:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV=

    "http://schemas.xmlsoap.org/soap/envelope/"

         xmlns:sat="http://example.org/satelliteSystem"

         xmlns:wsa="http://www.w3.org/2005/02/addressing"

         xmlns:wsrp=

    "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-

    ResourceProperties-1.2-draft-01.xsd">

     <SOAP-ENV:Header>

           <wsa:Action>

    http://docs.oasis-open.org/wsrf/2004/06/WS-

    ResourceProperties/GetResourcePropertyResponse

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/myClient

           </wsa:To>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:GetResourcePropertyResponse

                 xmlns:satProp=

                 "http://example.com/satellite">

              <satProp:altitude>

              47700

              </satProp:altitude>

           </wsrp:GetResourcePropertyResponse>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    在本例中,Header 信息并不引用服務(wù),而是引用客戶機(jī); http://example.com/myClient 是應(yīng)該接收響應(yīng)的客戶機(jī)的 URI。在大多數(shù)情況下,這與發(fā)出請(qǐng)求的客戶機(jī)是相同的,但是您也可以使用 wsa:Reply-To 元素將響應(yīng)發(fā)送到別的地方。

    在實(shí)際的消息體中還有一個(gè)標(biāo)準(zhǔn)元素 wsrp:GetResourcePropertyResponse,但是在本例中,它包含請(qǐng)求的實(shí)際屬性,以及它的當(dāng)前值。

    現(xiàn)在來看這在 WSDL 文件中是什么樣的。

    l         WSDL 文件

    為了將這些功能添加到應(yīng)用程序,我們需要將它們添加到 WSDL 文件,但是因?yàn)槲覀兪褂靡呀?jīng)定義好的標(biāo)準(zhǔn)消息交換模式,所以我們只需要添加一個(gè)新操作,像下面這樣:

    <?xml version="1.0" encoding="UTF-8"?>

    <definitions name="Satellite"

        targetNamespace="http://example.com/satellite"

        xmlns="http://schemas.xmlsoap.org/wsdl/"

        xmlns:tns="http://example.com/satellite"

        xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"

        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

        xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/

        wsrf-WS-ResourceProperties-1.2-draft-01.xsd"

        xmlns:wsrpwsdl=

        "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-

        ResourceProperties-1.2-draft-01.wsdl"

        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

       

        <wsdl:import namespace=

    "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"

                  location="WS-ResourceProperties.wsdl" />

       

     <types>

          <xsd:schema targetNamespace="http://example.com/satellite"

              xmlns:xsd="http://www.w3.org/2001/XMLSchema">

     ...

         </xsd:schema>

           

        </types>

     <message name="CreateSatelliteRequest">

          <part name="request" element="tns:createSatellite"/>

     </message>

       

     <message name="CreateSatelliteResponse">

          <part name="response" element="tns:createSatelliteResponse"/>

     </message>

       

     <portType name="SatellitePortType"

               wsrp:ResourceProperties="tns:GenericSatelliteProperties">

          <operation name="createSatellite">

              <input message="tns:CreateSatelliteRequest"

                  wsa:Action="http://example.com/CreateSatellite" />

              <output message="tns:CreateSatelliteResponse"

                  wsa:Action="http://example.com/CreateSatelliteResponse" />

          </operation>

          <operation name="getAltitude">

              <input message="wsrpwsdl:GetResourcePropertyRequest"

                  wsa:Action="http://docs.oasis-open.org/wsrf/2004/

                  06/WS-ResourceProperties/GetResourceProperty/>

                <output message="wsrpwsdl:GetResourcePropertyResponse"

                    wsa:Action="http://docs.oasis-open.org/wsrf/2004/

                    06/WS-ResourceProperties/GetResourcePropertyResponse/>

            </operation>

        </portType>

        <binding name="SatelliteSoapBinding" type="tns:SatellitePortType">

            <soap:binding style="document"

                transport="http://schemas.xmlsoap.org/soap/http"/>

            <operation name="createSatellite">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="getAltitude">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

        </binding>

        <service name="SatelliteService">

            <port name="SatellitePort" binding=

            "tns:SatelliteSoapBinding">

                <soap:address location=

                "http://example.com/satellite"/>

            </port>

        </service>

    </definitions>

    一開始是 portType,我們創(chuàng)建一個(gè)叫做 getAltitude 的新操作。該操作具有一個(gè) input 和一個(gè) output 消息,但是兩個(gè)消息都已經(jīng)定義在我們以前導(dǎo)入的 WS-ReferenceProperties.wsdl 文件中,所以我們需要做的就是使用適當(dāng)?shù)拿Q空間別名來引用它們。

    一旦創(chuàng)建了 operation,我們只要將它添加到 binding 就行了,而這一點(diǎn)我們已經(jīng)很內(nèi)行了。

    l         請(qǐng)求多個(gè)屬性

    幸運(yùn)的是,我們并不局限于檢索單個(gè)屬性值。我們也可以檢索多個(gè)屬性:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

            xmlns:sat="http://example.org/satelliteSystem"

            xmlns:wsa="http://www.w3.org/2005/02/addressing"

            xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-Resour

    ceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

                http://docs.oasis-open.org/wsrf/2004/06/

                WS-ResourceProperties/GetMultipleResourceProperties

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/satellite

           </wsa:To>

           <sat:SatelliteId>SAT9928</sat:SatelliteId>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:GetMultipleResourceProperties

                  xmlns:satProp="http://example.com/satellite">

              <wsrp:ResourceProperty>

              satProp:roll

              </wsrp:ResourceProperty>

              <wsrp:ResourceProperty>

              satProp:pitch

              </wsrp:ResourceProperty>

              <wsrp:ResourceProperty>

              satProp:yaw

              </wsrp:ResourceProperty>

           </wsrp:GetMultipleResourceProperties>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    同前面一樣,Header 中的信息來自端點(diǎn)引用。

    l         接收多個(gè)屬性

    響應(yīng)消息類似于它的單個(gè)屬性對(duì)應(yīng)物:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

             xmlns:sat="http://example.org/satelliteSystem"

             xmlns:wsa="http://www.w3.org/2005/02/addressing"

             xmlns:wsrp="http://docs.oasis-open.org/wsrf/200

             4/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

                http://docs.oasis-open.org/wsrf/2004/06/WS-Res

                ourceProperties/GetMultipleResourcePropertiesResponse

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/myClient

           </wsa:To>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:GetMultipleResourcePropertiesResponse    

                   xmlns:satProp="http://example.com/satellite">

              <satProp:roll>32</satProp:roll>

              <satProp:pitch>49</satProp:pitch>                    

              <satProp:yaw>0</satProp:yaw>

           </wsrp:GetMultipleResourcePropertiesResponse>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    同樣,我們要將它添加到 WSDL 文件。

    l         WSDL 文件

    同樣,因?yàn)槲覀儌鬟f的實(shí)際消息已經(jīng)定義在 WS-ResourceProperties.wsdl 文件中,把該功能添加到應(yīng)用程序所要做的就是創(chuàng)建一個(gè)新 operation:

    ...

        <message name="CreateSatelliteRequest">

            <part name="request" element=

            "tns:createSatellite"/>

        </message>

       

       <message name="CreateSatelliteResponse">

            <part name="response" element=

            "tns:createSatelliteResponse"/>

        </message>

       

        <portType name="SatellitePortType"

               wsrp:ResourceProperties =

               "tns:GenericSatelliteProperties">

            <operation name="createSatellite">

                <input message="tns:CreateSatelliteRequest"

                     wsa:Action=

                     "http://example.com/CreateSatellite" />

                <output message="tns:CreateSatelliteResponse"

                     wsa:Action=

                     "http://example.com/CreateSatelliteResponse" />

            </operation>

           

            <operation name="getAltitude">

                <input message=

                "wsrpwsdl:GetResourcePropertyRequest"

                     wsa:Action="http://docs.oasis-open.org/ws

                     rf/2004/06/WS-ResourceProperties/GetResourceProperty"/>

                <output message=

                "wsrpwsdl:GetResourcePropertyResponse"

                     wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

                     6/WS-ResourceProperties/GetResourcePropertyResponse"/>

            </operation>

           

            <operation name="getOrientation">

                <input message="wsrpwsdl:

                GetMultipleResourcePropertiesRequest"

                     wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

                     6/WS-ResourceProperties/GetMultipleResourceProperties"/>

                <output message=

                "wsrpwsdl:GetMultipleResourcePropertiesResponse"

                     wsa:Action=

                     "http://docs.oasis-open.org/wsrf/2004/06/WS-ResourcePro

                     perties/GetMultipleResourcePropertiesResponse"/>

            </operation>

           

        </portType>

       

        <binding name="SatelliteSoapBinding" type=

        "tns:SatellitePortType">

           <soap:binding style="document"

                  transport=

                  "http://schemas.xmlsoap.org/soap/http"/>

            <operation name="createSatellite">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="getAltitude">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="getOrientation">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

        </binding>

       

        <service name="SatelliteService">

            <port name="SatellitePort" binding="tns:SatelliteSoapBinding">

                <soap:address location="http://example.com/satellite"/>

            </port>

        </service>

    </definitions>

    一旦我們將 getOrientation operation 添加到了 binding,它就可以由應(yīng)用程序使用了。

    我們也可以查詢屬性,正如您馬上就會(huì)看到的。

    l         使用 XPath 查詢

    盡管請(qǐng)求所需的屬性相當(dāng)直觀,但是也有需要使用其他方法的情景。不是簡(jiǎn)單地按名稱請(qǐng)求資源屬性,我們可以使用 XPath 中可用的查詢。(有關(guān) XPath 的更多信息,請(qǐng)參閱 參考資料。)例如,如果不能確定某個(gè)特定的屬性是否存在,您可能想要在屬性上使用 XPath 函數(shù)。

    XPath 的另一個(gè)有用功能是,能夠請(qǐng)求多個(gè)相同命名的屬性,或者甚至能夠查詢參數(shù)。我們將在“理解 WSRF(第 2 部分)”中做前一件事,而馬上就會(huì)做后一件事。例如,我們可以與 boolean() 函數(shù)一起使用一個(gè) XPath 表達(dá)式,來確定人造衛(wèi)星是否指向正確的方向,而不用顯式地分析數(shù)據(jù):

    <SOAP-ENV:Envelope xmlns:SOAP-ENV=

    "http://schemas.xmlsoap.org/soap/envelope/"

            xmlns:sat="http://example.org/satelliteSystem"

            xmlns:wsa="http://www.w3.org/2005/02/addressing"

            xmlns:wsrp="http://docs.oasis-open.org/wsrf/20

            04/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

                http://docs.oasis-open.org/wsrf/2004/06/WS-ResourcePro

                perties/QueryResourceProperties

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/satellite

           </wsa:To>

           <sat:SatelliteId>SAT9928</sat:SatelliteId>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:QueryResourceProperties>

              <wsrp:QueryExpression Dialect=

              "http://www.w3.org/TR/1999/REC-xpath-19991116">

                 boolean(/*/pitch=25 and /*/roll=0 and /*/yaw=10)

              </wsrp:QueryExpression>

           </wsrp:QueryResourceProperties>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    注意 Dialect 屬性的使用,以區(qū)分 XPath V1.0 (這里展示的)和 XPath V2.0(http://www.w3.org/TR/2003/WD-xpath20-20031112)。規(guī)范沒有限制您可以支持的方言(dialect),但是如果實(shí)現(xiàn)不認(rèn)識(shí) Dialect,它就會(huì)返回一個(gè) fault 和錯(cuò)誤。

    l         查詢結(jié)果

    結(jié)果看起來非常像前面的兩個(gè)響應(yīng):

    <SOAP-ENV:Envelope xmlns:SOAP-ENV=

    "http://schemas.xmlsoap.org/soap/envelope/"

            xmlns:sat="http://example.org/satelliteSystem"

            xmlns:wsa="http://www.w3.org/2005/02/addressing"

            xmlns:wsrp="http://docs.oasis-open.org/wsrf/20

            04/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

                http://docs.oasis-open.org/wsrf/2004/06/

                WS-ResourceProperties/Quer

    yResourcePropertiesResponse

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/myClient

           </wsa:To>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:QueryResourcePropertiesResponse>

               false

           </wsrp:QueryResourcePropertiesResponse>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    在本例中,我們只是返回一個(gè)布爾值,但是您可以返回 XPath 可以返回的任何類型的值。

    l         WSDL 文件

    同樣,我們向 WSDL 文件添加一個(gè)新 operation:

    ...

        <portType name="SatellitePortType"

              wsrp:ResourceProperties=

              "tns:GenericSatelliteProperties">

    ...

          <operation name="getOrientation">

              <input message=

              "wsrpwsdl:GetMultipleResourcePropertiesRequest"

                  wsa:Action="http://docs.oasis-open.org/wsrf/20

                04/06/WS-ResourceProperties/GetMultipleResourceProperties"/>

              <output message=

              "wsrpwsdl:GetMultipleResourcePropertiesResponse"

                  wsa:Action="http://docs.oasis-open.org/wsrf/2004/06/W

              S-ResourceProperties/GetMultipleResourcePropertiesResponse"/>

          </operation>

           

            <operation name="checkOrientation">

                <input message=

                "wsrpwsdl:QueryResourcePropertiesRequest"

                    wsa:Action="http://docs.oasis-open.org/wsrf/20

                    04/06/WS-ResourceProperties/QueryResourceProperties"/>

                <output message=

                "wsrpwsdl:QueryResourcePropertiesResponse"

                    wsa:Action="http://docs.oasis-open.org/wsrf/2004/06/W

                 S-ResourceProperties/QueryResourcePropertiesResponse"/>

            </operation>

           

        </portType>

       

        <binding name="SatelliteSoapBinding" type=

        "tns:SatellitePortType">

            <soap:binding style="document"

                transport="http://schemas.xmlsoap.org/soap/http"/>

    ...

            <operation name="getOrientation">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                   <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="checkOrientation">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

        </binding>

       

        <service name="SatelliteService">

            <port name="SatellitePort" binding=

            "tns:SatelliteSoapBinding">

                <soap:address location=

                "http://example.com/satellite"/>

            </port>

        </service>

    </definitions>

    這關(guān)注檢索屬性?,F(xiàn)在來看設(shè)置屬性的值。

    l         我們想要完成什么

    至此,我們創(chuàng)建了一個(gè) WS-Resource,并且了解了一個(gè)或多個(gè)用于表示它的狀態(tài)的屬性。但是這與真正地操縱 WS-Resource 沒有太大的關(guān)系。在本節(jié)中,我們來看添加、懸掛和刪除 WS-Resource 的屬性。

    至此,我們的人造衛(wèi)星已經(jīng)在天空中相對(duì)于地球的軌道中穩(wěn)定了,而不是觀測(cè)到某些特定的東西了。在本節(jié)中,我們要添加一個(gè) ResourceProperty,它表示一個(gè)特定的目標(biāo)。然后我們通過更新位置屬性將人造衛(wèi)星移向該目標(biāo),然后再刪除所創(chuàng)建的目標(biāo)屬性。最后,通過將適當(dāng)?shù)牟僮魈砑拥?WSDL 文件,我們將把所有事情綜合在一起。

    l         添加屬性

    向 WS-Resource 添加屬性涉及到使用 Insert 元素:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

             xmlns:sat="http://example.org/satelliteSystem"

             xmlns:wsa="http://www.w3.org/2005/02/addressing"

             xmlns:wsrp="http://docs.oasis-open.org/wsrf/

         2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

               http://docs.oasis-open.org/wsrf/2004/06/W

               S-ResourceProperties/SetResourceProperties

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/satellite

           </wsa:To>

           <sat:SatelliteId>SAT9928</sat:SatelliteId>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:SetResourceProperties

                  xmlns:satProp="http://example.com/satellite">

               <wsrp:Insert>

                   <satProp:targetCoords>

                   36n11, 115w08

                   </satProp:targetCoords>

               </wsrp:Insert>

           </wsrp:SetResourceProperties>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    我們可以給這個(gè)新屬性取任何好聽的名字,但是我們必須允許該新元素在 Resource Properties 文檔中。(當(dāng)我們?cè)?WSDL 文件 中調(diào)整 WSDL 文件時(shí)將來做這一件事。)

    l         添加屬性的結(jié)果

    當(dāng)成功添加、刪除或更改屬性之后,我們將會(huì)得到一個(gè)只是確認(rèn)操作的響應(yīng)消息:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV=

    "http://schemas.xmlsoap.org/soap/envelope/"

              xmlns:sat="http://example.org/satelliteSystem"

              xmlns:wsa="http://www.w3.org/2005/02/addressing"

              xmlns:wsrp="http://docs.oasis-open.org/wsrf/

        2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

                http://docs.oasis-open.org/wsrf/2004/06/W

        S-ResourceProperties/SetResourcePropertiesResponse

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/myClient

           </wsa:To>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:SetResourcePropertiesResponse>

           </wsrp:SetResourcePropertiesResponse>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    該響應(yīng)與 Update 和 Delete 操作產(chǎn)生的響應(yīng)是相同的。

    l         更改屬性值

    在 添加屬性 中,我們添加了一個(gè)新屬性,但是我們也能更改現(xiàn)有屬性的值。例如,我們可以告訴系統(tǒng),通過使用 Update 元素更改人造衛(wèi)星的位置屬性來移動(dòng)人造衛(wèi)星:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV=

    "http://schemas.xmlsoap.org/soap/envelope/"

           xmlns:sat="http://example.org/satelliteSystem"

           xmlns:wsa="http://www.w3.org/2005/02/addressing"

           xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/0

        6/wsrf-WS-ResourceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

                http://docs.oasis-open.org/wsrf/2004/06/WS-Re

           sourceProperties/SetResourceProperties

          </wsa:Action>

          <wsa:To SOAP-ENV:mustUnderstand="1">

               http://example.com/satellite

          </wsa:To>

         <sat:SatelliteId>SAT9928</sat:SatelliteId>

     </SOAP-ENV:Header>

     <SOAP-ENV:Body>

         <wsrp:SetResourceProperties

                 xmlns:satProp="http://example.com/satellite">

             <wsrp:Update>

                <satProp:latitude>36.11</satProp:latitude>

             </wsrp:Update>

             <wsrp:Update>

                <satProp:longitude>158.08</satProp:latitude>

             </wsrp:Update>

          </wsrp:SetResourceProperties>

       </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    在本例中,我們使用了兩個(gè) Update 組件,但是我們實(shí)際上可以使用 Insert、Update 和 Delete 組件的任意組合。

    l         刪除屬性

    屬性可以被完全刪除。例如,如果我們決定不再觀測(cè)某個(gè)特定的目標(biāo),就可以刪除該屬性:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

             xmlns:sat="http://example.org/satelliteSystem"

             xmlns:wsa="http://www.w3.org/2005/02/addressing"

             xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-Resour

    ceProperties-1.2-draft-01.xsd">

        <SOAP-ENV:Header>

           <wsa:Action>

             http://docs.oasis-open.org/wsrf/2004/06/WS-Resou

             rceProperties/SetResourceProperties

           </wsa:Action>

           <wsa:To SOAP-ENV:mustUnderstand="1">

                http://example.com/satellite

           </wsa:To>

           <sat:SatelliteId>SAT9928</sat:SatelliteId>

        </SOAP-ENV:Header>

        <SOAP-ENV:Body>

           <wsrp:SetResourceProperties

                    xmlns:satProp="http://example.com/satellite">

               <wsrp:Delete resourceProperty="targetCoords"/>

           </wsrp:SetResourceProperties>

        </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    同樣,我們的資源屬性文檔的模式定義必須允許我們做這一更改。

    l         WSDL 文件

    同樣,因?yàn)闃?biāo)準(zhǔn)元素已經(jīng)定義在 WS-ResourceProperties.wsdl 中,所以我們可以簡(jiǎn)單地添加新操作:

    <?xml version="1.0" encoding="UTF-8"?>

    <definitions name="Satellite"

        targetNamespace="http://example.com/satellite"

        xmlns="http://schemas.xmlsoap.org/wsdl/"

        xmlns:tns="http://example.com/satellite"

        xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"

        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

        xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/

        wsrf-WS-ResourceProperties-1.2-draft-01.xsd"

        xmlns:wsrpwsdl="http://docs.oasis-open.org/wsrf/200

    4/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"

        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

       

        <wsdl:import namespace="http://docs.oasis-open.org/

     wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.wsdl"

            location="WS-ResourceProperties.wsdl" />

       

        <types>

            <xsd:schema

              targetNamespace="http://example.com/satellite"

                xmlns:xsd="http://www.w3.org/2001/XMLSchema">

               

                <xsd:import namespace=

          "http://schemas.xmlsoap.org/ws/2004/03/addressing"

                       schemaLocation="WS-Addressing.xsd" />

               

               <xsd:element name="createSatellite">

                   <xsd:complexType/>

               </xsd:element>

               

               <xsd:element name="createSatelliteResponse">

                   <xsd:complexType>

                       <xsd:sequence>

                           <xsd:element ref=

                           "wsa:EndpointReference"/>

                       </xsd:sequence>

                   </xsd:complexType>

               </xsd:element>

               

              <xsd:element name="latitude" type="xsd:float" />

              <xsd:element name="longitude" type="xsd:float" />

              <xsd:element name="altitude" type="xsd:float" />

              <xsd:element name="pitch" type="xsd:float" />

              <xsd:element name="yaw" type="xsd:float" />

              <xsd:element name="roll" type="xsd:float" />

              <xsd:element name="focalLength" type="xsd:float" />

              <xsd:element name="currentView" type="xsd:string" />

               

              <xsd:element name="GenericSatelliteProperties">

                  <xsd:complexType>

                      <xsd:sequence>

                          <xsd:element ref="latitude" minOccurs="1"

                          maxOccurs="1"/>

                          <xsd:element ref="longitude" minOccurs="1"

                          maxOccurs="1"/>

                          <xsd:element ref="altitude" minOccurs="1"

                          maxOccurs="1"/>

                          <xsd:element ref="pitch" minOccurs="1"

                          maxOccurs="1"/>

                          <xsd:element ref="yaw" minOccurs="1"

                          maxOccurs="1"/>

                          <xsd:element ref="roll" minOccurs="1"

                          maxOccurs="1"/>

                          <xsd:element ref="focalLength"

                          minOccurs="1" maxOccurs="1"/>

                          <xsd:element ref="currentView"

                          minOccurs="1" maxOccurs="1"/>

                          <xsd:any/>

                      </xsd:sequence>

                  </xsd:complexType>

               </xsd:element>

               

            </xsd:schema>

           

        </types>

        <message name="CreateSatelliteRequest">

            <part name="request" element="tns:createSatellite"/>

        </message>

       

        <message name="CreateSatelliteResponse">

            <part name="response" element=

            "tns:createSatelliteResponse"/>

        </message>

       

        <portType name="SatellitePortType"

                 wsrp:ResourceProperties=

                 "tns:GenericSatelliteProperties">

            <operation name="createSatellite">

                <input message="tns:CreateSatelliteRequest"

           wsa:Action="http://example.com/CreateSatellite" />

                <output message="tns:CreateSatelliteResponse"

                    wsa:Action=

              "http://example.com/CreateSatelliteResponse" />

            </operation>

           

            <operation name="getAltitude">

                <input message=

                "wsrpwsdl:GetResourcePropertyRequest"

                  wsa:Action="http://docs.oasis-open.org/wsr

    f/2004/06/WS-ResourceProperties/GetResourceProperty"/>

                <output message=

                "wsrpwsdl:GetResourcePropertyResponse"

          wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

    6/WS-ResourceProperties/GetResourcePropertyResponse"/>

            </operation>

           

            <operation name="getOrientation">

                <input message=

             "wsrpwsdl:GetMultipleResourcePropertiesRequest"

          wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

    6/WS-ResourceProperties/GetMultipleResourceProperties"/>

                <output message=

            "wsrpwsdl:GetMultipleResourcePropertiesResponse"

                          wsa:Action=

    "http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceProp

    erties/GetMultipleResourcePropertiesResponse"/>

            </operation>

           

            <operation name="checkOrientation">

                <input message=

                    "wsrpwsdl:QueryResourcePropertiesRequest"

                   wsa:Action="http://docs.oasis-open.org/wsr

    f/2004/06/WS-ResourceProperties/QueryResourceProperties"/>

                <output message=

                   "wsrpwsdl:QueryResourcePropertiesResponse"

           wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

    6/WS-ResourceProperties/QueryResourcePropertiesResponse"/>

            </operation>

           

            <operation name="addTarget">

                <input message=

                      "wsrpwsdl:SetResourcePropertiesRequest"

           wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

    6/WS-ResourceProperties/SetResourceProperty"/>

                <output message=

                     "wsrpwsdl:SetResourcePropertiesResponse"

           wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

    6/WS-ResourceProperties/SetResourcePropertyResponse"/>

            </operation>

            <operation name="moveToTarget">

                <input message=

                      "wsrpwsdl:SetResourcePropertiesRequest"

           wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

    6/WS-ResourceProperties/SetResourceProperty"/>

                <output message=

                     "wsrpwsdl:SetResourcePropertiesResponse"

           wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

    6/WS-ResourceProperties/SetResourcePropertyResponse"/>

            </operation>

            <operation name="removeTarget">

                <input message=

                      "wsrpwsdl:SetResourcePropertiesRequest"

                     wsa:Action="http://docs.oasis-open.org/ws

    rf/2004/06/WS-ResourceProperties/SetResourceProperty"/>

                <output message=

                     "wsrpwsdl:SetResourcePropertiesResponse"

           wsa:Action="http://docs.oasis-open.org/wsrf/2004/0

    6/WS-ResourceProperties/SetResourcePropertyResponse"/>

            </operation>

           

        </portType>

       

        <binding name="SatelliteSoapBinding"

        type="tns:SatellitePortType">

            <soap:binding style="document" transport=

                    "http://schemas.xmlsoap.org/soap/http"/>

            <operation name="createSatellite">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="getAltitude">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="getOrientation">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

           <operation name="checkOrientation">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="addTarget">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="moveToTarget">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

            <operation name="removeTarget">

                <input>

                    <soap:body use="literal"/>

                </input>

                <output>

                    <soap:body use="literal"/>

                </output>

            </operation>

        </binding>

       

        <service name="SatelliteService">

            <port name="SatellitePort"

            binding="tns:SatelliteSoapBinding">

                <soap:address location=

                "http://example.com/satellite"/>

            </port>

        </service>

    </definitions>

    還請(qǐng)注意,我們可以添加任意元素到 GenericSatelliteProperties,所以我們可以容易地添加新屬性,比如 targetCoords。

    l         結(jié)束語

    在本教程,也即 4 篇關(guān)于 WSRF 的系列文章中的第一篇文章中,我們一開始解釋了 WSRF 背后的目的,以及為什么單有 Web 服務(wù)還不夠。然后解釋了 WS-Resource 是有狀態(tài)資源(比如數(shù)據(jù)庫或衛(wèi)星)與 Web 服務(wù)的組合。

    資源本身是由一系列屬性來描述的,這些屬性是與 WSDL 文件中的 Web 服務(wù)相關(guān)聯(lián)的。我們還介紹了 WSDL 和 WS-Addressing 的基礎(chǔ),WSRF 使用 WS-Addressing 來指向一個(gè)特定的 WS-Resource 實(shí)例。

    我們介紹了創(chuàng)建 WS-Resources,了解了它們的屬性,以及調(diào)整這些屬性,以便操縱資源。

    在本系列的以后部分中,我們將會(huì)介紹 WSRF 的一些更高級(jí)的用途,比如 ServiceGroups 和錯(cuò)誤處理,以及 WS-Notifications。在本系列的最后一部分中,我們將把所有內(nèi)容綜合在一起,并編寫一個(gè)應(yīng)用程序,它使用類來實(shí)現(xiàn)本系列前兩部分中討論的每個(gè)概念。

    l         參考資料

    Web 服務(wù)資源框架(Web Services Resource Framework,WSRF)涉及大量不同領(lǐng)域。下面是起步所需的一些參考資料:

    單擊 下載本教程中介紹的完整 WSDL 文件。

    WSRF 和相關(guān)規(guī)范

    WSRF 文檔 的主要位置在 Globus Alliance Web 站點(diǎn)上,但是最新的規(guī)范可以在 Oasis 處找到。文檔包括:

    Web 服務(wù)資源框架(白皮書)

    The WS-Resource Framework

    WS-ResourceProperties (WSRF-RP)

    WS-ResourceLifetime (WSRF-RL)

    WS-ServiceGroup (WSRF-SG)

    WS-Base Faults (WSRF-BF)

    Web 服務(wù)和相關(guān)的規(guī)范



    Author: orangelizq
    email: orangelizq@163.com

    歡迎大家訪問我的個(gè)人網(wǎng)站 萌萌的IT人
    posted on 2007-11-07 22:04 桔子汁 閱讀(1375) 評(píng)論(1)  編輯  收藏 所屬分類: Web Service

    評(píng)論:
    # re: 理解WSRF之一 使用WS-ResourceProperties (整理自IBM網(wǎng)站) 2007-11-23 10:34 | aier
    主站蜘蛛池模板: 国产在线19禁免费观看国产| 亚洲色欲色欲www在线播放 | 哒哒哒免费视频观看在线www | 含羞草国产亚洲精品岁国产精品| 久久精品网站免费观看| 国产AV旡码专区亚洲AV苍井空| 亚洲第一成年免费网站| 亚洲AV成人影视在线观看| 最近的中文字幕大全免费版| 亚洲日本一线产区和二线产区对比 | 亚洲午夜无码久久久久| 中国一级特黄的片子免费 | 亚洲伊人tv综合网色| 免费v片在线观看视频网站| 亚洲中字慕日产2021| 毛片高清视频在线看免费观看| 中国china体内裑精亚洲日本| 好男人看视频免费2019中文| 激情无码亚洲一区二区三区 | 亚洲AV无码乱码在线观看牲色| 高潮毛片无遮挡高清免费| 亚洲日本中文字幕一区二区三区| A国产一区二区免费入口| 亚洲成av人片在线观看无码不卡| 国产成人免费视频| 亚洲成a人片在线网站| 无码视频免费一区二三区 | 亚洲女人影院想要爱| 国产精品视频永久免费播放| 亚洲AV综合色区无码一二三区| 又黄又爽的视频免费看| 本免费AV无码专区一区| 亚洲三级电影网站| 我们的2018在线观看免费高清| 亚洲国产成人久久精品软件| 亚洲国产综合人成综合网站| 91国内免费在线视频| 亚洲国产成人手机在线电影bd| 日韩在线视频免费看| 一本大道一卡二大卡三卡免费| 亚洲成A∨人片在线观看不卡|