Web サービス・リソース・フレームワークを使用したステートフル Web サービスの作成

ステートフル Web サービスを WS-Resource として実装し、WS-Addressing エンドポイント参照を使用して、それを参照することができます。WS-Resources は、通常の Web サービスと同じ方法で、同じツールを使用して開発します。ただし、このトピックで説明しているように、実行しなければならない追加のタスクがいくつかあります。

このタスクについて

このタスクは、WS-Resource を作成する場合に実行します。WS-Resource は、ステートフル・リソースと、リソースへのアクセスに使用される Web サービスの組み合わせです。このタスクを完了するには、標準 Web サービス開発タスク、および Web サービス・リソース・フレームワーク (WSRF) 仕様の知識を持っている必要があります。WSRF 仕様への入門としては、OASIS WSRF Primer 文書をお読みください。

手順

  1. WS-Resource がアクセスを提供するリソース・コンポーネントを識別、または作成します。 このリソース・コンポーネントは、既存のシステムまたはエンティティーであるか、あるいは新規コンポーネントである場合があります。 リソースを実装する方法に制約はありません。 単純な Java™ クラス、ステートレス・セッション・エンタープライズ Bean、リレーショナル・データベースによってサポートされるエンティティー Bean、サービス・データ・オブジェクト (SDO)、Java コネクター、またはその他のコンポーネントが使用可能です。
  2. WS-Resource 用のリソース・プロパティー・スキーマ文書を識別、または作成します。 IBM® Rational® Application Developer for WebSphere®、 または任意の XML スキーマ・オーサリング・ツールを使用して、XML スキーマを作成します。 スキーマは、リソース・プロパティー文書のルート・エレメント用に、XML complexType エレメントを定義します。
  3. WS-Resource の Web サービス・コンポーネント用の WSDL 文書を作成または生成します。 WSDL ファイルの作成について詳しくは、JAX-RPC アプリケーション用の WSDL ファイルの開発を参照してください。
  4. WSDL ファイルを編集して、ResourceProperties 属性を portType エレメントに追加します。 この属性は、前に作成したリソース・プロパティー文書のルート・エレメントを識別します。 例えば、Printer サービスが、名前空間 http://example.org/printer 内にルート・エレメント <printer_properties> を伴うリソース・プロパティー文書を持っている場合、wsdl:portType エレメントは以下のように見えます。
    <wsdl:portType xmlns:pr="http://example.org/printer"  
                   xmlns:wsrf-rp="http://docs.oasis-open.org/wsrf/rp-2"
                   name="Printer" wsrf-rp:ResourceProperties="pr:printer_properties">
  5. WS-Resource を指示する EndpointReference を入手するための方法を提供します。 「Create」と呼ばれる wsdl:operation エレメントを定義すると、それは、型 EndpointReferenceType の wsdl:output メッセージを戻します。 Printer WS-Resource に EndpointReference を戻す CreatePrinter オペレーションの例については、を参照してください。
  6. WS-Resource が wsdl:portType エレメントの子エレメントとしてサポートする、それぞれの WSRF 定義のオペレーションを定義します。 ポート・タイプでサポートされるそれぞれの WSRF 定義のオペレーションについて、それぞれの wsdl:message エレメント上で WS-Addressing action 属性を指定します。 例えば、GetResourceProperty オペレーションは WSDL 内で以下のように定義されます。
    <wsdl:operation name="GetResourceProperty" 
                    xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
                    xmlns:wsrf-rpw="http://docs.oasis-open.org/wsrf/rpw-2">
      <wsdl:input name="GetResourcePropertyRequest" message="wsrf-rpw:GetResourcePropertyRequest"
        wsaw:Action="http://docs.oasis-open.org/wsrf/rpw-2/GetResourceProperty/GetResourcePropertyRequest"/>
      <wsdl:output name="GetResourcePropertyResponse" message="wsrf-rpw:GetResourcePropertyResponse"
        wsaw:Action="http://docs.oasis-open.org/wsrf/rpw-2/GetResourceProperty/GetResourcePropertyResponse"/>
      ...
    </wsdl:operation>
    wsaw:Action 属性は、デフォルトの URI 値ではなく、WSRF 定義の wsaw:Action URI が WSRF 定義のメッセージのために使用されることを確実にします。
    注: ResourceProperties 属性が PortType エレメント上にある場合は、WS-ResourceProperties 仕様には GetResourceProperty オペレーションの存在が必要となります。
  7. Web Services Addressing を使用する JAX-RPC Web サービス・アプリケーションの作成のステップ 2 からの指示に従 って、WS-Resource の実装を作成し、クライアント がエンドポイント参照を使用して WS-Resource にアクセスできるようにし、アプリケーションをデプロイします。

WS-Resource 用リソース・プロパティー・スキーマ文書の作成

以下の例は、この手順のステップ 2 から 4 に対応しています。 これらの例では、IT 組織が WS-Resource インスタンスを使用してプリンターのネットワークを管理する方法を示しています。 WS-Resource は、リソースと、そのリソースにアクセスするための Web サービスとの組み合わせです。 以下の例では、該当の組織が Web サービスを使用して、Web Services Addressing を使用する JAX-RPC Web サービス・アプリケーションの作成の例で設定されているようにプリンター・ネットワークを現在管理していると想定しています。

Web Services Resource Framework (WSRF) 仕様の一部である WS-Resource 仕様で記述されているように、WS-Resource へのアクセスは、WS-Addressing エンドポイント参照で行われ、 そのリソースの状態の表示内容は、リソース・プロパティー XML 文書で維持されます。 ステートフル・リソースを表記するための WS-Resource の使用によって、標準化された Web サービス・メッセージを使用して、リソースの状態表記と対話する相互作用手法が提供されます。

WS-Resource には、XML スキーマで記述されたリソース・プロパティー XML 文書が必要です。 この文書は、WS-Resource の状態を特定の視点から記述するものです。 プリンターの WS-Resource スキーマ文書は、以下の例のようになります。
<?xml version="1.0"?>
<xsd:schema ...
   xmlns:pr="http://example.org/printer.xsd"
   targetNamespace="http://example.org/printer.xsd" >
 <xsd:element name="printer_properties">
   <xsd:complexType>
     <xsd:sequence>
        <xsd:element ref="pr:printer_reference" />
        <xsd:element ref="pr:printer_name" />
        <xsd:element ref="pr:printer_state" />
        <xsd:element ref="pr:printer_accepting_jobs" />
        <xsd:element ref="pr:queued_job_count" />
        <xsd:element ref="pr:operations_supported" />
        <xsd:element ref="pr:document_format_supported" />
        <xsd:element ref="pr:job_hold_until_default" 
                     minOccurs="0" />
        <xsd:element ref="pr:job_hold_until_supported" 
                     minOccurs="0"
                     maxOccurs="unbounded" />
        <xsd:element ref="wsrf-rp:QueryExpressionDialect" 
                     maxOccurs="unbounded" />
        <xsd:element ref="pr:job_properties" minOccurs="0" 
                     maxOccurs="unbounded" />
     </xsd:sequence>
   </xsd:complexType>
 </xsd:element>
 ...
</schema>
プリンターの WS-Resource サーバーの WSDL 定義は、WS-Addressing 例の場合と同じですが、wsdlPortType エレメントに関する ResourceProperties 属性が追加されています。汎用 Web サービスではなく、WS-Resource によってポート・タイプを実装することを、この属性によって宣言します。リソース・プロパティー文書タイプ宣言が、 インターフェースに含まれているため、 このインターフェースには、WSRF 定義の GetResourceProperty オペレーションも含める必要があります。 このオペレーションは、WS-ResourceProperties 仕様で必須のものとなっています。
<wsdl:definitions targetNamespace="http://example.org/printer" ...
             xmlns:wsrf-rp="http://docs.oasis-open.org/wsrf/rp-2"
             xmlns:wsrf-rpw="http://docs.oasis-open.org/wsrf/rpw-2"
             xmlns:wsa="http://www.w3.org/2005/08/addressing"
             xmlns:pr="http://example.org/printer">
  <wsdl:types>
    ...
    <xsd:schema...>
      <xsd:element name="CreatePrinterRequest"/>
      <xsd:element name="CreatePrinterResponse" 
                   type="wsa:EndpointReferenceType"/>
	    	    <xsd:import namespace="http://www.w3.org/2005/08/addressing" 
                  schemaLocation="http://www.w3.org/2005/08/addressing/ws-addr.xsd"/>
	    	    <xsd:import namespace=http://docs.oasis-open.org/wsrf/rp-2
                  schemaLocation="http://docs.oasis-open.org/wsrf/rp-2.xsd"/>
    </xsd:schema> 
    <!-- Import WSDL definitions for GetResourceProperties -->
	  	  <wsdl:import namespace="http://docs.oasis-open.org/wsrf/rpw-2" 
                 location="http://docs.oasis-open.org/wsrf/rpw-2.wsdl" />

  </wsdl:types>
  <wsdl:message name="CreatePrinterRequest">
    <wsdl:part name="CreatePrinterRequest" 
               element="pr:CreatePrinterRequest" />
  </wsdl:message>
  <wsdl:message name="CreatePrinterResponse">
    <wsdl:part name="CreatePrinterResponse" 
               element="pr:CreatePrinterResponse" />
  </wsdl:message>

  <!-- The port type has a ResourceProperties attribute that references the resource 
  properties document -->
  <wsdl:portType name="Printer" wsrf-rp:ResourceProperties="pr:printer_properties">
    <wsdl:operation name="createPrinter">
      <wsdl:input name="CreatePrinterRequest" 
                  message="pr:CreatePrinterRequest" />
      <wsdl:output name="CreatePrinterResponse"
                   message="pr:CreatePrinterResponse" />
    </wsdl:operation>

    <!-- The GetResourceProperty operation is required by the WS-ResourceProperties specification -->
    <wsdl:operation name="GetResourceProperty" 
        <wsdl:input name="GetResourcePropertyRequest" 
                    message="wsrf-rpw:GetResourcePropertyRequest" 
                    wsa:Action="http://docs.oasis-open.org/wsrf/rpw-2/GetResourceProperty/
                                                                        GetResourcePropertyRequest"/>
        <wsdl:output name="GetResourcePropertyResponse"
                     message="wsrf-rpw:GetResourcePropertyResponse" 
                     wsa:Action="http://docs.oasis-open.org/wsrf/rpw-2/GetResourceProperty/
                                                                       GetResourcePropertyResponse"/>
        <wsdl:fault name="ResourceUnknownFault"
                    message="wsrf-rw:ResourceUnknownFault"/>
        <wsdl:fault name="InvalidResourcePropertyQNameFault"
                    message="wsrf-rpw:InvalidResourcePropertyQNameFault" />     
    </wsdl:operation>
  </wsdl:portType>
</wsdl:definitions>

トピックのタイプを示すアイコン タスク・トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_wsrf
ファイル名:twbs_wsrf.html