示例:创建 WS-Notification 拉出点
使用此任务为 JAX-RPC 订户客户机编写代码。此客户机创建拉出点以供使用拉出样式通知的用户应用程序使用。
关于此任务
本示例的依据是,将 Java™ API for XML-based remote procedure calls (JAX-RPC) API 与使用 WSDL2Java 工具生成的代码(此代码针对创建 WS-Notification 服务点时生成的通知代理 WSDL 运行)以及 WebSphere® Application Server API 和 SPI 配合使用。
在 WebSphere Application Server 中,WS-Notification 服务有两个实现:V6.1 和 V7.0。此 JAX-RPC 示例可与 V6.1 或 V7.0 WS-Notification 服务点成功交互。 但是,如果要将 WS-Notification 与策略集配合使用(例如,启用与 WS-ReliableMessaging 的组合),那么 WS-Notification 应用程序必须编码为使用 Java API for XML-based Web Services (JAX-WS) 编程模型,并且必须与 V7.0 WS-Notification 服务点交互。 如果您不熟悉 JAX-WS 客户机应用程序编程,请参阅下列主题:
要为充当订户角色的 JAX-RPC 客户机编写代码,请创建拉出点以供要使用拉出样式通知的用户应用程序使用,完成以下步骤(参阅示例代码摘录以了解进一步信息)。
过程
- 查找 JAX-RPC 服务。 JNDI 名称特定于您的 Web Service 客户机信息。
- 获取要对其调用操作的端口的存根。
- 创建请求信息。
- 通过对存根调用关联方法来调用 CreatePullPoint 操作。
- 从响应中检索对拉出点的引用。
- 从响应中检索所有其他信息。
示例
以下示例代码描述以订户角色执行操作的 JAX-RPC 客户机创建拉出点以供要使用拉出样式通知的用户应用程序使用:
// Look up the JAX-RPC service. The JNDI name is specific to your web services client implementation
InitialContext context = new InitialContext();
javax.xml.rpc.Service service = (javax.xml.rpc.Service) context.lookup(
"java:comp/env/services/NotificationBroker");
// Get a stub for the port on which you want to invoke operations
NotificationBroker stub = (NotificationBroker) service.getPort(NotificationBroker.class);
// Create the request information.
SOAPElement[] optionalInformation = null;
CreatePullPoint cpp = new CreatePullPoint(optionalInformation);
// Invoke the CreatePullPoint operation by calling the associated method on the stub
CreatePullPointResponse response = stub.createPullPoint(cpp);
// Retrieve the reference to the pull point from the response
EndpointReference pullPointEPR = response.getPullPoint();
// Retrieve any additional information from the response
SOAPElement[] additionalInformation = response.getElements();