java 异步 Web 服务 SOAP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10877223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Asynchronous web service SOAP
提问by Mickael Marrache
I have an interface that I've exposed as a regular SOAP web service. One method of the interface consists for the client to send a file to the server, then the server processes the file and returns a result file. Processing the file may take some time, so I think using asynchronous invocation of this method is a better idea. I thought about the following flow:
我有一个作为常规 SOAP Web 服务公开的接口。该接口的一种方法是客户端向服务器发送文件,然后服务器处理该文件并返回结果文件。处理文件可能需要一些时间,所以我认为使用这种方法的异步调用是一个更好的主意。我想到了以下流程:
The client invokes the asynchronous method and sends the file using an attachment (MTOM). When the file is received by the server, a response is sent back to the client indicating that the file has been received and that it will be processed shortly. Once the file is processes, a response is sent back to the client indicating it has been processed and a result file is returned in the response also as an attachment.
客户端调用异步方法并使用附件 (MTOM) 发送文件。当服务器接收到该文件时,会向客户端发送一个响应,指示该文件已被接收并且将很快处理该文件。一旦文件被处理,一个响应被发送回客户端,表明它已经被处理,结果文件也作为附件在响应中返回。
Is it possible using SOAP with CXF?
是否可以将 SOAP 与 CXF 一起使用?
Thanks
谢谢
采纳答案by UVM
You can use Callback
approach of Asynchronous InvocationModel
.
您可以使用Callback
的方法Asynchronous InvocationModel
。
Callback approach - in this case, to invoke the remote operation, you call another special method that takes a reference to a callback object (of javax.xml.ws.AsyncHandler type) as one of its parameters. Whenever the response message arrives at the client, the CXF runtime calls back on the AsyncHandler object to give it the contents of the response message
回调方法 - 在这种情况下,要调用远程操作,您可以调用另一个特殊方法,该方法将回调对象(javax.xml.ws.AsyncHandler 类型)的引用作为其参数之一。每当响应消息到达客户端时,CXF 运行时都会回调 AsyncHandler 对象以将响应消息的内容提供给它
More information can be had from the following:
可以从以下内容获得更多信息:
回答by giocarmine
If you use some tool like WSDL2Java for client generation, you can even choose to generate an asynchronous client. It will generate for you a callback handler with empty methods for each of the service operations and exceptions of the service. You then can just implement those methods to set the actions to do when the response is received. Remember that when an asynchronous call is done a new thread is started.
如果您使用诸如 WSDL2Java 之类的工具来生成客户端,您甚至可以选择生成一个异步客户端。它将为您生成一个回调处理程序,其中包含针对每个服务操作和服务异常的空方法。然后,您可以实现这些方法来设置在收到响应时要执行的操作。请记住,当异步调用完成时,将启动一个新线程。
回答by sudmong
Yes, Once you receive the file, you may return the request id to client and start processing on server side and do maintain various states of processing. Client can come back in different interval, and will receive the processing status or the output if it is completed.
是的,一旦您收到文件,您就可以将请求 ID 返回给客户端并在服务器端开始处理并维护各种处理状态。客户端可以在不同的时间间隔内返回,如果完成,将收到处理状态或输出。