File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Question about Invoking a Web Service Asynchronously Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Question about Invoking a Web Service Asynchronously" Watch "Question about Invoking a Web Service Asynchronously" New topic

Question about Invoking a Web Service Asynchronously

Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361
I head read a tutorial about invoking a Web Service asynchronously, and seen there are two approaches to accomplish this from an API point of view :

  • Polling
  • Callback

  • As a programmatic [API] point of view, this is well understood, but my question is about the Socket layer of the asynchronous web service invocation.

    My imagination for it, is that, a client sends a request, and the server (may) take(s) a lot of time to process the request. In this time, the socket connection is not closed, but when the server finishes processing, it sends the response back to the client over the same socket connection, where the whatever JAX-WS classes catch it and passes it to the Callback classes.

    Is my understanding of asynchronous web services correct ??

    Thanks in advance.

    Life is the biggest school
    Ivan Krizsan
    Ranch Hand

    Joined: Oct 04, 2006
    Posts: 2198
    This matter is further complicated by the fact that JAX-WS has an asynchronous client model, which is what you described with your "imagination".
    To enumerate the available options:
  • Synchronous invocation

  • The invocation do not return until the operation has finished processing.

  • Asynchronous one-way invocation

  • Also called "fire-and-forget". The request is sent to the web service but no response will be given. The client can continue to execute despite the request not having finished being processed, because the client does not need to wait for a result. When using a HTTP binding, there will be a confirmation that the request has reached the server, which the client must wait for.

  • Asynchronous client

  • The web service is still a regular, synchronous web service. The difference is on the client side, where a request is sent and and a special thread is dispatched to await the result. The client can learn about the result either by a special object being called back when a result is available or by polling a response-object to examine if the operation has completed an a response is available.
    In both cases, a timeout can be specified that limits the time the client waits for a result.
    The client will never be called back, or need to poll, the web service - everything regarding the asynchronous invocation is taken care of on the client side.

  • Asynchronous web service.

  • The web service is asynchronous and supplies an operation with which clients can submit a task to the service.
    There are two different ways by which clients can obtain the result of a task:
    1. Polling.
    The web service supplies another operation which the clients can invoke to check if a task has been processed, supplying a correlation identifier of some kind that tells the service which task the client wants to know about.
    2. Callback.
    The clients must provide a service which will be invoked by the web service to which the client submitted a task when the task has been processed.

    A lot of text , hope things are more clear!
    Best wishes!

    Khaled Mahmoud
    Ranch Hand

    Joined: Jul 15, 2006
    Posts: 361
    Thanks Ivan for the wonderful explanation . You saved me a lot of time searching and reading.

    So most the asynchronous Web Service implementation lies on the developer for the web service.

    Ramakrishna Udupa
    Ranch Hand

    Joined: Aug 09, 2013
    Posts: 254
    Hi All,

    I'm a beginner for web-service.
    @Ivan Krizsan Nice explanation. Can you give a sample example for each web-service. I found explanation in google search but not a proper code.

    Ramakrishna K.C
    Abhay Agarwal
    Ranch Hand

    Joined: Feb 29, 2008
    Posts: 1341

    Thanks Ivan for this explanation.
    subject: Question about Invoking a Web Service Asynchronously
    jQuery in Action, 3rd edition