使用 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 文档。
过程
创建 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>