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

10.4 Implementing the Client

One the client-side, we need to send a request for weather updates, using the generated sample client WeatherSummaryClient.cpp. It does the following:

For each step, the code writes to standard out the WeatherSummary object being sent or received as verification that the service is running as expected.

10.4.1 The Request-Response Operation

First we have the implementation for invoke_getSummary(), which sends a request for a weather summary to the server and marshals out the returned WeatherSummary object:

//1Invokes the getSummary() method in the proxy and places the WeatherSummary object returned into ws.
//2Marshals the WeatherSummary object as an XML document.
//3Catches any faults returned from the server and prints them.

10.4.2 The One Way Operation

Next we have the implementation for invoke_updateWeather(), which creates a WeatherSummary object and sends it to the server as a one-way weather update message.

//1Creates a WeatherSummary object.
//2Populates WeatherSummary object with some data.
//3This and the following lines create parameters to be used in the method call. These parameters are derived from the listener created in the main() method (described below). They communicate to the server the transport type and location being used to send the message.
//4Marshals the WeatherSummary object as an XML document.
//5Sends a one-way message to the server with the weather summary update.

10.4.2.1 Putting it All Together in the main() Function

Finally, here is the code that appears in the main() function of the client implementation:

//1Because notification is involved, the generated code starts a listener for the appropriate transport to listen for incoming notifications.
//2Creates a rwsf::Transport instance. The code that follows (not shown) determines the correct transport and assigns it to this instance.
//3Creates a proxy instance using one of the make() convenience functions of the proxy class. Notice that the previously determined correct transport is passed as a parameter.
//4Checks that creation of the proxy has succeeded.
//5Invokes the service operation method for request-response.
//6Invokes the service operation method for one-way messages. Notice that the listener is sent as a parameter so the invocation function can obtain information on the transport, host, and port being used.
//7//7-//9These lines of code determine when, if ever, notification has ended, which allows the listerner to be shut down and the client to exit. The first line obtains the handle class of the notification implementation. The next line obtains the body for that handle. The third line says to continue processing until the call to finalMessageReceived() returns true.
//10 Shuts down the listener for notification messages.

10.4.3 Implementing the Client-Side Notification

Three extra classes are generated on the client side to support the notification pattern.

In addition, three client-specific configuration files are used:

The code below is an excerpt from WeatherSummaryNotificationImp.cpp. This code receives the notification operation method from the server.

//1Registers the client notification implementation as a message handler.
//2Function polled by line //9 of the client implementation code.
//3Marshals the WeatherSummary object received in the notification message as an XML document.
//4Sets done_ equal to true so that finalMessageReceived() returns true, causing the client to shut down the listener and exit.

In this example, after the server sends its last notification, it immediately sends a renewal request to the client as a solicit-response operation. As discussed earlier, a working application would use some other event to trigger this message, but for the purposes of this example, the code has been simplified.

10.4.4 Implementing Client Side Solicit-Response

The code below is taken from WeatherSummaryNotificationImp.cpp. This code receives the message from the server and sends a response, using the solicit-response service operation method weatherUpdateRenew().

//1Receives the renewal request from server.
//2Creates a string response to contain the answer, and prints a status message.
//3Sets done_ to true to shut down the listener, and returns response.

10.4.5 Transport Configuration File Supporting Notification

This is a part of the client-transports.xml file that supports client notification.

In the highlighted line above, note that the "port" properties are commented out, allowing the listener location for the client notification to be dynamically assigned. If you do not want a dynamic assignment, uncomment these properties and enter values for port. For more information on assigning a listener a location, either through dynamic assignment or specifically, see Section 11.4, "Autoconfiguring Listeners."



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.