wood burning stoves 2.0*
The moose likes Web Services and the fly likes Asynchronous Web service call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Asynchronous Web service call" Watch "Asynchronous Web service call" New topic

Asynchronous Web service call

Sathiesh Kumar Vs
Ranch Hand

Joined: Oct 24, 2010
Posts: 31

I am in a position to use Axis2 - Jax WS and create a web service which will be processing some records that might take a few secs. Now this web service call needs to be asynchronous as the client should not be waiting for me to process and they need to keep sending me requests.

In this case, what should I do ? Should I have some extra binding information in the wsdl to make is asynchronous support ?
Or since its a https service on a WAS server, can I still access the service asynchronously using any client side logic without making any change in the wsdl and the server side. If the latter can be done, does that mean, by default my simple web service can be called asynchronously ?

Also, am little confused here over synchronous/ asynchronous and sequential/parallel processing of my records.

Please guide me

Thanks and Regards,
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12678
Why not divide the problem?

1. A call to start processing a set of records - reply is "ok" or "unable to start"

2. A call to see if processing is complete - reply is "yes" or "no" or "error prevented processing"

3. A call to get the results


Java Resources at www.wbrogden.com
Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
As you know in J2ee environment asynchronous processing can be achieved using a Queue in the middle.
When a webservice needs to be asynchronous it is SOAP over JMS instead of SOAP over http/https.
The endpoint url looks different when it is a asynchronous webservice . It has information like the queue factory embeded in it.
You can refer the below link to do this .

Alternatively you can code a regular webservice (SOAP over Https) and have the webservice just post the message on to queue.
The business logic can then reside in the MDB.
Though this approach is not truely synchronous , the time the client has to wait for a response is very negligible as the webservice does nothing more than just post the message on to a queue. The webservice can just return a empty respose if you decide to have generic faults like service unavailable.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
If you are using JAX-WS and wsimport to generate the client artifacts, you can generate client artifacts that will contain asynchronous versions (as well as regular, synchronous, version) of operation stubs using a binding file.
The binding file is to look like this:

As you can see, you need to specify the following things in the binding file:
1. The location of the WSDL for which you are creating client artifacts.
2. The port type which contain the operation(s) you want to be able to invoke asynchronously.
3. The operation(s) you want to be able to invoke asynchronously.

As you generate client artifacts with wsimport, you add the -b option and the path to the binding file.
For a complete example, see section 4.8 of my SCDJWS 5 Study Notes available here: http://www.slideshare.net/krizsan/scdjws-5-study-notes-3085287

Finally, I want to stress that the web service in itself does not change - it remains synchronous. However, the client thread sending requests to the web service will be able to proceed doing other things immediately after having sent the request and process the response of the request at some later point in time when it is available.
Best wishes!

My free books and tutorials: http://www.slideshare.net/krizsan
Sathiesh Kumar Vs
Ranch Hand

Joined: Oct 24, 2010
Posts: 31
Thanks guys..

I cannot go with dividing into separate calls as again, that would increase the service hits for me
Also configuring MDB is little difficult because I need to configure in all the servers i Use

Ivan, your suggestion would suit me.
I am using RAD to create this web service. Which again uses ws:import i guess.
Here, how would I link this external binding file to WSDL,so that my server stubs will have the Async methods generated.
I tried out looking over the web, but couldn't find the exact way of doing it.
Can you please advice me, how will import this external binding file to my WSDL ?

Guys, Again thanks for your replies
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Satiesh,
You should see this http://today.java.net/pub/a/today/2006/09/19/asynchronous-jax-ws-web-services.html, which I think suits very much to your requirement.

When a webservice needs to be asynchronous it is SOAP over JMS instead of SOAP over http/https.

Not anymore in JAX-WS

(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Sathiesh Kumar Vs
Ranch Hand

Joined: Oct 24, 2010
Posts: 31
Hi guys,

As I mentioned earlier, I am using RAD7 to generate these stubs.. Not sure if that is the problem. When I am generating server stubs with the external binding <enableAsyncMapping>true</enableAsyncMapping> stubs are creating generated but when publishing the service I am getting an exception :

com.ibm.ws.exception.RuntimeWarning: javax.xml.ws.WebServiceException: The server-side SEI com.americanexpress.ws.jupiter.postitinerary.PostItineraryService contains the asynchronous method postItineraryAsync. Asynchronous methods are not allowed for server-side artifacts.

Can anyone suggest what s the problem ?
Also, like using wsimport for client stubs, how can I generate server stubs ? Please help.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516

Since you mentioned that you are using Axis2, have you checked their documentation on asynchronous calls. Does this suit you ?


Sathiesh Kumar Vs
Ranch Hand

Joined: Oct 24, 2010
Posts: 31
Yes Raja,

The approaches in the document suit me very well..

When I am trying to use Client side asynchrony, I am having problems in creating the ServiceClient as at runtime, i am getting many NoClassDefFound and ClassCastExceptions which are because of missing proper runtime dependent jars..

When I tried the server side asynchrony, The service is not publishing saying that the server side artifacts cannot have asynchronous methods
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516

Hi Satish,

May be I have missed reading this point earlier, but are you looking for client side asynchrony or serverside asynchrony. Personally I have not tried serverside asynchrony, but in your case, if you are looking for client side asynchrony, I guess, you can easy have the missing jar files. It would have mentioned about the class it was looking for in the exception. As I mentioned, please try to look into AXIS 2 documentation, for better understanding.
Sathiesh Kumar Vs
Ranch Hand

Joined: Oct 24, 2010
Posts: 31
I tried my possibilities at server side and i couldn't do it... For client side asynchrony, I followed the example given at


which uses ServiceClient API, Now am not getting exceptions as i downloaded the jars and added..

Now, when I call the service, I am able get the logs only printed on the client side, but not the code written in my service impl or call back handler...
Any idea of what would be the problem ?
Sathiesh Kumar Vs
Ranch Hand

Joined: Oct 24, 2010
Posts: 31
hi guys,

Got the issue resolved.. Thanks for your support
Chris Partridge

Joined: Dec 27, 2012
Posts: 1
Hi Sathiesh,

can you post what the resolution was? I am having a similar issue.

Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 227
@Sathiesh Kumar Vs

Can you post simple client and server classes. My requirement is,

I want to trigger the threads(in JAVA proj. exposed as web-service) when Request is made. That request should trigger threads and no need of response to client. I mean, he click's the button from UI(JSP) , the request triggers threads, Response is a simple message from Jquery. In Java(back-end) the threads should do all works. For this I need Asynchronous Web service call.

Ramakrishna K.C
I agree. Here's the link: http://aspose.com/file-tools
subject: Asynchronous Web service call
Similar Threads
How does client poll the interaction layer to get the result of WS invocation?
Asynchronous web service
Can any web service be called Asynchronously
Asynchronous call in the Server side?.,
Different Message Exchange Pattern interfaces