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 and receive weather updates, using the provided sample client implementation WeatherSummaryClient.cpp. It does the following:

For each step, the code writes status information to standard out to verify that the client and server are behaving as expected.

10.4.1 Setting up a Listener

The first task during the client initialization is to set up a listener so the client can receive request messages from the server. Notification and solicit-response require the server to establish the connection and the client to be listening for it.

//1

Creates a service handler for the client. The handler WeatherSummaryNotificationService is defined in the generated file client-handlers.xml.

//2

Creates a listener object based on whether the information available is a transport name or a location.

//3

If the constructed listener is confirmed as valid, starts the listener, and registers the service handler.

10.4.2 The Request-Response Service Operation Call

As another part of client initialization, the subscribe()method sends location and transport information to the weather service so the client can receive weather updates via its listener.

//1

Using logic similar to that for creating the listener, determines the transport to be used in creating the proxy.

//2

Creates the proxy based on the transport object passed into the static make() method.

//3

Acquires server, port, and transport scheme information from the listener.

//4

Creates two objects to be passed in the service request that will hold the response data.

//5

Sends the subscribe request message.

//6

Prints out information about whether the subscription succeeded based on the status value returned by the request. The status value is based on the results of the verifySubscription() solicit-response operation on the server. This operation simply sends a request to the client, which responds true if the request is received. See Section 10.4.4, "Implementing the Client-Side Notification and Solicit-Response Endpoints," for the code.

The client also implements an unsubscribe() method that is very similar to subscribe().

10.4.3 The One Way Operation Call

After subscribing to the notification service, the client implementation makes a one-way proxy call that sends updated local weather data to the weather service one-way service endpoint. It does not receive a response to this message because it is one way. However, after the message is sent it receives a notification message from the server since it previously subscribed to receive notifications.

//1

Creates a WeatherSummary object. This is a complex datatype defined in a schema in the WeatherSummary WSDL file. The HydraExpress XML Binding feature generates C++ classes that allow you easily to manipulate this data in your code.

//2

Populates the WeatherSummary object with some data.

//3

Uses the proxy to send this data to the weather service.

10.4.4 Implementing the Client-Side Notification and Solicit-Response Endpoints

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 from WeatherSummaryNotificationImp.cpp. It shows both the weatherNotification() method that handles the notification message initiated by the server, and the endpoint implementation representing the client response to the server's verifySubscription() solicit-response message.

//1

Registers the client notification implementation as a message handler.

//2

Prints out the data in the incoming notification message from the server.

//3

Responds true to the server's verifySubscription message to indicate that the client is reachable from the server. This is the implementation of the solicit-response message endpoint.

10.4.5 Transport Configuration File Supporting Notification

This is a part of the client-transports.xml file that configures a listener to support client notification and solicit-response endpoints.

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 this line and enter the desired value for port. For more information on assigning a listener a location, either through dynamic assignment or specifically, see Section 11.4, "Using an Autoconfigured Listener."



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo are registered trademarks of Rogue Wave Software, and HydraExpress is a trademark of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.