Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
HydraExpress Web Service Development Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

13.3 The Async Example

Let's take a look at the shipped example Async located in your <installdir>\tutorials\webservices\Async directory. This example illustrates two service operation methods that are implemented asynchronously, one a request/response method, the other a one-way method.

For more information on one-way operations and how they work, see Section 9.2.3, "The One Way Pattern."

This section discusses how to implement the client's asynchronous service operation methods and assumes knowledge of how to generate code and build a client. For background information on creating a client with various options, see Chapter 7, "Developing Clients."

13.3.1 Implementing the Request/Response Method Asynchronously

Following is the implementation of the request/response invoke() method in AsyncClient.cpp, the provided implementation of the client.

//1A request/response method that simulates a wait in order to illustrate its asynchronous behavior.
//2Calls the asynchronous process start() method.
//3Tests whether the response is available, calling isFinished() on the handle.
//4Retrieves the response.
//5If the response message rwsf::CallInfo object has data of interest, retrieves the object so calls can be made against it.
//6Calls the asynchronous process End() method, which in this position causes the client to block until the response arrives.
//7Catches a rwsf::SoapFaultException.

13.3.2 Implementing the One-Way Method Asynchronously

This section discusses implementing a one-way method asynchronously. Even though a one-way method expects no response, you may wish to implement it asynchronously, allowing you to make another call on the proxy without waiting for the transport to return.

This discussion assumes background knowledge on one-way methods and how they work. For information, see Section 9.2.3, "The One Way Pattern."

Now let's look at the implementation of the one-way invoke() method in AsyncClient.cpp in the <installdir>\tutorials\Async directory.

//1Invoking a one-way method that expects no response.
//2Because no response is expected with a one-way method, the generator prints "Invoking one-way method" to std::out to indicate to the user that the service is doing its work.
//3Calling the End() method, while it may seem counter-intuitive for a one-way method, allows the main thread to block until the thread that is preparing and sending the one-way message has completed its work. This also protects against exiting the program while the threads are still executing.
//4Calls the asynchronous oneWayMethodStart() on the proxy, assigning the result to an async handle. This method returns immediately, even though not everything necessary may have been done to send the message.
//5Note that there is no catch block for rwsf::SoapFaultExceptions for one-way operations, since they will never be thrown.

13.3.3 Running the Async Example


Make sure that you have set up your environment as described in Chapter 2, "Installation," in the HydraExpress User's Guide. On Windows, be sure you have set up your command window with the MSVC environment.

To run this example:

  1. Generate code by opening a command prompt and navigating to the directory <installdir>\tutorials\webservices\Async. Enter

  2. to direct HydraExpress to generate code into the directory AsyncExample based on the Async.wsdl. You could also enter the options and WSDL file manually, as follows:

  3. Before building this example, copy the provided sample files from the <installdir>\tutorials\webservices\Async to the new AsyncExample directory, allowing the provided files to overwrite the generated files, as follows:

  4. Navigate to the directory AsyncExample, and build the example by entering nmake (Win32) or make (UNIX/Linux).

  5. To deploy the service, shut down the Agent servlet container if it is running, run nmake (Windows) or make (Linux or UNIX) for the deploy target, and restart the server. The command sequence to deploy the service is shown below:

    Win32

    %RWSF_HOME%\bin\rwsfserver stop

    nmake deploy

    %RWSF_HOME%\bin\rwsfserver start

    UNIX/Linux

    $RWSF_HOME/bin/rwsfserver stop

    make deploy

    $RWSF_HOME/bin/rwsfserver start

  6. Change to the directory, AsyncExample\bin, and run the client by entering

  7. The service returns the following:



Previous fileTop of DocumentContentsIndex pageNext file

©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.