使用 Web Service 资源框架来创建有状态的 Web Service

可以将有状态 Web Service 作为 WS-Resource 来实现,并通过使用 WS-Addressing 端点引用对其进行引用。可以使用相同工具按开发普通 Web Service 的方式来开发 WS-Resource。但是,必须完成一些其他任务,如本主题中所述。

关于此任务

如果需要创建 WS-Resource,即对有状态资源与用于访问该资源的 Web Service 进行组合,请完成本任务。要完成本任务,必须了解标准 Web Service 开发任务以及 Web Service 资源框架 (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 Service 组件创建或生成 WSDL 文档。 有关创建 WSDL 文件的信息,请参阅开发 JAX-RPC 应用程序的 WSDL 文件
  4. 编辑该 WSDL 文件以将 ResourceProperties 属性添加到 portType 元素。此属性标识先前创建的资源属性文档的根元素。 例如,如果打印机服务的资源属性文档带有根元素 <printer_properties> 且名称空间为 http://example.org/printer,那么 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 消息。请参阅相关内容,以获取对打印机 WS-Resource 返回 EndpointReference 对象的 CreatePrinter 操作示例。
  6. 将 WS-Resource 支持的每个 WSRF 定义的操作定义为 wsdl:portType 元素的子元素。 对于受端口类型支持的每个 WSRF 定义的操作,在每个 wsdl:message 元素上指定 WS-Addressing action 属性。 例如,在 WSDL 中定义了 GetResourceProperty 操作,如下所示:
    <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 属性确保 WSRF 定义的 wsaw:Action URI(而不是缺省 URI 值)用于 WSRF 定义的消息。
    注: 如果 PortType 元素上有 ResourceProperties 属性,那么 WS-ResourceProperties 规范要求存在 GetResourceProperty 操作。
  7. 遵循创建使用 Web service 寻址的 JAX-RPC Web Service 应用程序中步骤 2 的指示信息以创建 WS-Resource 的实现,使客户机能够通过端点引用来访问 WS-Resource 以及部署应用程序。

创建 WS-Resource 的资源属性模式文档

以下示例对应于过程中的步骤 2 到步骤 4。以下示例显示 IT 组织如何使用 WS-Resource 实例来管理打印机网络。WS-Resource 是资源与用来访问该资源的 Web Service 的组合。这些示例假定组织当前正在使用 Web Service 来管理其打印机网络,如创建使用 Web service 寻址的 JAX-RPC Web Service 应用程序中的示例所述。

如 WS-Resource 规范(它是 Web Service 资源框架 (WSRF) 的一部分)中所述,WS-Resource 是通过 WS-Addressing 端点引用来访问的,而且它的资源状态的视图在资源属性 XML 文档中进行维护。通过使用 WS-Resource 来表示有状态的资源,可以提供一种可互操作方法以通过使用标准化 Web Service 消息来与资源的状态表示进行交互。

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 属性。此属性声明端口类型是由 WS-Resource 实现而不是由通用 Web Service 实现。因为该接口包含资源属性文档类型声明,所以该接口还必须包含 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