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

3.4 The Generated Application Samples

By default, HydraExpress produces sample client and service implementations. For the operation sayHello located at portType GreetingPortType, its code generator produces:


The files in the project\app directory are meant to be edited and used to implement your client and service. The files in the project\codegen directory provide background functionality and should not be edited.

To implement the client and server, you can implement the methods in these generated sample implementations, or create your own implementations. In most cases, modifying the sample implementation is the simplest approach.

For this example, we will use provided implementations, which are located directly in the HelloWorld directory, as follows:

The following sections explain how to use the client and server implementations.

3.4.1 The Client Proxy

Class GreetingBindingProxy is the generated client proxy for the HelloWorld service. It provides five methods for each operation specified in the WSDL file. One pair of methods implements synchronous behavior, and the remaining three methods implement asynchronous behavior.

Excerpt from the client proxy for the HelloWorld service, GreetingBindingProxy.h:

//1Declares the first of the two synchronous sayHello() methods. Takes a standard string as the hello request. Returns a string in response.
//2Declares the second synchronous sayHello() method, which takes a standard string as the hello request, and a string as source data. This method also explicitly passes a rwsf::CallInfo object. Use this method if you need to add your own SOAP or transport headers to the message, or if you want to add some additional message handlers for the outgoing message.
//3Defines the first of the two asynchronous sayHello() methods. These methods return a handle to an object that can be used to check on whether the operation has completed, and to retrieve the data if it has.
//4Defines the second asynchronous sayHello() method. Differs from the first asynchronous method only in that it explicitly passes a rwsf::CallInfo object, which plays the same role as it does in the corresponding synchronous method.
//5Declares the end method for an asynchronous process, which is used in retrieving the data.

To send a message to the Web service, we must construct an instance of the proxy and invoke either the synchronous or asynchronous method(s) that correspond to the WSDL operation. The method returns the values defined in the WSDL file for the response message.

3.4.1.1 Using the Client Proxy and the Client Implementation

We use the client proxy to implement the HelloWorld client application. The generated sample implementations by default use one of the proxy's synchronous methods, as shown here:

This section discusses implementing the client for a synchronous operation. For information on asynchronous operations, see Chapter 13, "Asynchronous Messaging."

The following code shows the provided client implementation file, <installdir>\tutorials\HelloWorld\GreetingPortClient.cpp. The client implementation is not a class, but rather a source file that includes the proxy header file and a main() function that invokes the proxy's methods. The code below is reformatted slightly to fit on the page:

//1Include necessary header files.
//2Function that invokes the sayHello() operation. The function takes a reference to a GreetingBindingProxy, creates a standard string "World!" and an empty standard string instance, and calls the sayHello operation on the proxy. The client generator implements one sample invocation method that takes an explicit rwsf::CallInfo parameter. The program provides a try block around the code that calls methods on the proxy. The proxy indicates errors by throwing a rwsf::SoapFaultException derived from rwsf::SoapFault, and the server writes a log message by default. Note that the generator makes no attempt to provide valid input for the operation.
//3The main() function first determines the location for the service through a combination of information from the WSDL and possible command line options and arguments. If no command line argument is used when invoking the client, the default is the location specified in the WSDL. For more information about possible location and transport options when invoking the client at runtime, see Chapter 7.3.4, "Runtime Options."
//4Registers the service handlers and transports that are available for this message.
//5Obtains a client proxy and ensures that it is valid.
//6Calls the invoke_sayHello() method on the proxy.
//7Catch blocks for exceptions that might be thrown by this call. The exceptions shown should always be caught. If you generate code with the -SourcePro option, which uses Rogue Wave SourcePro C++ datatypes, then you should also catch exceptions derived from RWxmsg.

The sayHello operation requires an XML Schema string as input ("World!") and returns a message containing an XML Schema string that holds the string "Hello World!"

The next step is to develop the service implementation. Then we'll compile and run the application.

3.4.2 The Service Implementation

The GreetingPortType service operations are implemented by the service implementation class GreetingPortTypeImp.

To implement the server, you may either implement the methods of this class or derive your own class from GreetingPortTypeBase. In this tutorial, we will use the provided implementation GreetingPortTypeImp located at <installdir>\tutorials\HelloWorld.

//1Include headers.
//2This macro registers your service, requiring only the default name for the implementation class as an argument.
//3Implements the service operation method sayHello() by returning a string "Hello."

Section 3.5 explains how to compile and run the example program.



Previous fileTop of DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.