精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-11-26
在旧的基于JAX-RPC的webservice编程model中,是不支持异步的service 调用的,在最新的Jax-ws webservice 编程model中,加入了对webservice的异步调用的支持。 当前Jax-ws 提供了两种编程模型。 a.An synchronous method import javax.xml.ws.Response; import itso.hello.HelloMessenger; import itso.hello.HelloMessengerService; import itso.hello.SayHelloResponse; public class HelloAsyncPollingClient { public static void main(String... args) throws Exception { HelloMessengerService service = new HelloMessengerService(); HelloMessenger port = service.getHelloMessengerPort(); Response<SayHelloResponse> sayHelloAsync = port.sayHelloAsync("Thilde"); //判断是否已经返回 while ( ! sayHelloAsync.isDone() ) { // Do something useful for now } // Web service endpoint has now responded: //取得包装过的返回对象 SayHelloResponse sayHelloResponse = sayHelloAsync.get(); //取得真实返回值 String message = sayHelloResponse.getReturn(); System.out.println(message); } } import itso.hello.HelloMessenger; import itso.hello.HelloMessengerService; import itso.hello.SayHelloResponse; import javax.xml.ws.AsyncHandler; import javax.xml.ws.Response; public class HelloAsyncCallbackClient { public static void main(String... args) throws Exception { HelloMessengerService service = new HelloMessengerService(); HelloMessenger port = service.getHelloMessengerPort(); port.sayHelloAsync("Teresa", new AsyncHandler<SayHelloResponse>() { public void handleResponse(Response<SayHelloResponse> res) { try { SayHelloResponse response = res.get(); String message = response.getReturn(); System.out.println(message); } catch (Exception e) { e.printStackTrace(); } } }); } } Map<String, Object> requestContext = ((BindingProvider)port).getRequestContext(): // Configure the client for wire-level asynchronous message exchange requestContext.put("com.ibm.websphere.webservices.use.async.mep", true);
当你启用这种异步message交换机制时,client端会在request发出后在一个单独的channel上来监听和接收response message.当然,client在发出request时,会使用WS-Addressing 来向server提供 ReplyTo endpoint reference(ERP),当请求发出去以后当前的这个connection就会关闭,当servicer处理完请求时,它会根据client端提供的ERP(ReplyTo endpoint reference)重新初始化一个connection 来发送一个response. 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 3754 次