示例:创建通知使用者 Web Service 框架

请在创建实现 NotificationConsumer portType 的 Web Service 时使用本示例,该 NotificationConsumer portType 由 Web Services Base Notification 规范定义。

关于此任务

此任务提供两个代码示例:
  • 一个 WSDL 文档示例,该示例描述了一个 Web Service,该 Web Service 实现了 Web Services Base Notification 规范定义的 NotificationConsumer portType。
  • 使用 WSDL2Java 工具根据以上 WSDL 文档生成的服务端点接口(SEI)的基本实现。
注: 为 WS-Notification 编写 JAX-WS 应用程序一文还包括使用者 Web Service 的示例。

过程

如果要创建通知使用者 Web Service 框架,请参阅以下代码示例。

示例

以下示例 WSDL 文档描述了一个 Web Service,该 Web Service 实现了 Web Services Base Notification 规范定义的 NotificationConsumer portType:

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

<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wsn-bw="http://docs.oasis-open.org/wsn/bw-2"
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="uri:example.wsn/consumer"
    targetNamespace="uri:example.wsn/consumer">

    <wsdl:import namespace="http://docs.oasis-open.org/wsn/bw-2"
                           location="http://docs.oasis-open.org/wsn/bw-2.wsdl" />

    <wsdl:binding name="NotificationConsumerBinding" type="wsn-bw:NotificationConsumer">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="Notify">
            <wsdlsoap:operation soapAction="" />
            <wsdl:input>
                <wsdlsoap:body use="literal" />
            </wsdl:input>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="NotificationConsumerService">
        <wsdl:port name="NotificationConsumerPort" binding="tns:NotificationConsumerBinding">
            <wsdlsoap:address location="http://myserver.mycom.com:9080/Consumer" />
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

以下示例显示了使用 WSDL2Java 工具根据以上 WSDL 文档生成的服务端点接口(SEI)基本实现:

public class ConsumerExample implements NotificationConsumer {
        
    public void notify(NotificationMessage[] notificationMessage, SOAPElement[] any) 
                                                                    throws RemoteException {
        // Process each NotificationMessage
        for (int i=0; i<notificationMessage.length; i++) {                
            NotificationMessage message = notificationMessage[i];
                
            // Get the contents of the message
            SOAPElement messageContent = message.getMessageContents();
                
            // Get the expression indicating which topic the message is associated with
            TopicExpression topic = message.getTopic();                
                
            // Get a reference to the producer (this value is optional and so might be null)
            EndpointReference producerRef = message.getProducerReference();
                
            // Get a reference to the subscription (this value is optional and so might be null)
            EndpointReference subscriptionRef = message.getSubscriptionReference();
                
            // User defined processing ...                

        }
    }
}

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjwsn_ex_cons
文件名:tjwsn_ex_cons.html