0
我们有一个asmx web服务。我必须使用WSDL测试客户端。我已经成功实现了客户端异步映射的代码。问题是我无法理解客户端如何向服务器发出多个同时请求。我看到Future
接口,但我不明白我如何使用它进行并发呼叫。异步JAX-WS多次调用
private void callAsyncCallback(String encodedString, String key) {
DataManipulation service = new DataManipulation();
try { // Call Web Service Operation(async. callback)
DataManipulationSoap port = service.getDataManipulationSoap12();
// TODO initialize WS operation arguments here
AsyncHandler<GetDataResponse> asyncHandler =
new AsyncHandler<GetDataResponse>() {
@Override
public void handleResponse(Response<GetDataResponse> response) {
try {
// TODO process asynchronous response here
System.out.println("Output at::: " + new Date().toString());
System.out.println("************************Result = " + response.get().getGetDataResult());
} catch (Exception ex) {
// TODO handle exception
}
}
};
Future<? extends Object> result = port.getDataAsync(encodedString,key, asyncHandler);
while (!result.isDone()) {
// do something
}
} catch (Exception ex) {
// TODO handle custom exceptions here
}
}
我知道我可以在while(!result.isDone())
循环做一些事情,但我怎么能在这里再次调用Web服务?
其目的是我必须发送多个文件到Web服务。 WS对这些文件执行一些操作并发回一些结果。我希望客户端同时发送所有文件,以便所需的时间非常短。我试过在代码中多次调用方法callAsyncCallback
,但只有当第一次调用返回到客户端时才会进入下一行。
编辑
谁能给我一些指点给ExecutorService的?我已经阅读了一些像invokeAll这样的选项,但我无法将其与JAX-WS相关联。任何帮助将不胜感激。
感谢