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

7.2 Developing and Running the Example

7.2.1 Service Description

The client created in this tutorial uses the WSDL provided in the file DayOfWeek.wsdl located in the tutorials\webservices\DayOfWeek directory of your HydraExpress distribution. The WSDL file defines a single operation, GetDayofWeek, located at a port named DayOfWeekPortType. Since this tutorial focuses on the various options available to a client rather than designing an implementation, the service is deliberately simple. The operation receives a message containing an XML Schema date part. The operation returns a message containing an XML Schema string that holds the day of the week on the date provided.

7.2.2 Invoking the Generator

Make sure that you have set up your environment as described in Chapter 2, "Installation," in the HydraExpress User's Guide.

Open a command prompt and change to the tutorials\webservices\DayOfWeek directory under the RWSF_HOME directory, as shown below:

Win32

cd %RWSF_HOME%\tutorials\webservices\DayOfWeek

UNIX/Linux

cd $RWSF_HOME/tutorials/webservices/DayOfWeek

In addition to the DayofWeek WSDL and the provided implementation files, this directory contains a HydraExpress project file, example-project.xml. This file provides custom configuration information to the generator. (For more information on the HydraExpress project file, see Section 22, "The Project File and Directory Structure."

If you open this file, you'll note that it identifies a value for the project-name attribute and a files element that references the DayofWeek.wsdl, so there is no need to include these items on the command line if this file is provided to the generator.

Run rwsfgen with example-project.xml as the sole argument, as follows:

The above invocation is exactly the same as the following:


The two required options above are -projectname and the name of the file to parse. The project name is required, and may be entered directly into a HydraExpress project file or on the command line. Note that the name may not include spaces, as HydraExpress supports only file paths without spaces.

Since this chapter is primarily interested in creating a client to access the service, we could also choose to generate only a client, using an additional argument -noserver as follows:

Since we will be using this example to also discuss server-side options in Chapter 7, we'll build both a client and server.

For full information on the various code generation options, see Chapter 21.6, "Generator Options."

HydraExpress generates server and client-side code, sample applications, configuration files, makefiles, MSVC project files, and documentation into a directory DayOfWeekExample, using the options included in the example-project.xml file. (HydraExpress supports only file paths without spaces, so when naming your project, do not include spaces, since HydraExpress uses the project name as a basis for the name of the code generation directory.)

Files are separated into several subdirectories according to type, as shown below:

The directory app contains the sample implementations for the server and client, and the directory include contains relevant include and header files organized under project name. The conf directory contains the various configuration XML files used to configure transports, handlers, and named objects on the server side. The directory codegen contains generated code used to implement the service. The contents of this directory should not be modified.

The generator also produces HTML documentation. Single-click access is provided through the index.html file in the docs directory.

The directories bin and lib are empty at code generation, but will include the .exe and .dll files, and the .lib or .so files after the project build, depending on your platform.

For more information on this directory structure, see Section 22.3, "The Code Generation Directory."

Table 4 lists the generated files.


Files that are overwrite-protected are generated with a ".sample" extension if a file exists in the code generation directory of the same name. See Section 21.7, "Overwrite Protection."

Table 4: Files generated for DayofWeek example 

DirectoryFilesDescription
DayOfWeekExample/
DayOfWeekExample.xml

The project file, named according to the project name, defining all project elements (options, configurations, schemas, WSDLs, etc.). See Section 22.2.


makefile
makefile_debug

Project-level makefiles. Calls all makefiles in subdirectories. Overwrite-protected.


makefile.include

Include makefile. Contains all makefile compiler and linker options. Edits to this file cascade down to all makefiles. Overwrite-protected.


[DayOfWeekExample.dsw or
DayOfWeekExample.sln]

MSVC 6 workspace or MSVC 7 solution files. Generated for Windows platforms, depending on value of -projectversion flag.


deployDebug.bat deployRelease.bat

Convenience debug and release deployment batch files generated for use with MSVC projects.

    app/
makefile
makefile_debug

Makefiles. Builds contents of app/ directory Overwrite-protected.

        /client
DayOfWeekPortClient.cpp

Sample client implementation using the client proxy. Overwrite-protected.


makefile
makefile_debug

Makefiles. Builds contents of app/client directory. Overwrite-protected.


[DayOfWeekPortClient.dsp or
DayOfWeekPortClient.vcproj]

MSVC6 or MSVC7 project files generated for Windows platforms.

        /server
DayOfWeekPortTypeImp.cpp
DayOfWeekPortTypeImp.h

Sample service implementation and header files. Derives from
MyService Base. Overwrite-protected.


makefile
makefile_debug

Makefiles. Builds contents of app/server directory. Overwrite-protected.


[DayOfWeekPortService.dsp or
DayOfWeekPortService.vcproj]

MSVC6 or MSVC7 project files generated for Windows platforms.

    codegen/
makefile
makefile_debug

Makefiles. Builds contents of codegen/ directory. Overwrite-protected.

        /client
DayofWeekBindingProxy.cpp

Implementation file for the generated client proxy class.


makefile
makefile_debug

Makefiles. Builds contents of codegen/client directory. Overwrite-protected.


[DayOfWeekBindingClientLibrary.dsp or
DayOfWeekBindingClientLibrary.vcproj]

MSVC6 or MSVC7 project files generated for Windows platforms.

        /server
DayOfWeekBindingSkeleton.cpp
DayOfWeekPortTypeBase.cpp

Implementation files for the class that handles messaging and the base class for the server-side implementation.


makefile
makefile_debug

Makefiles. Builds contents of codegen/server directory. Overwrite-protected.


[DayOfWeekPortService.dsp or
<DayOfWeekPortService.vcproj]

MSVC6 or MSVC7 project files generated for Windows platforms.

    conf/
server-transports.xml
client-transports.xml

Configuration files for:
1. Server and client transports


dayofweek_handlers.xml

2. Server-side handlers to support handler chaining and configuration


client-handlers.xml

3. Client-side handlers containing default client logger


dayofweek_objects.xml

4. All named objects required by this service. These are registered and created when the container is started.


dayofweek_web.xml

5. Service Descriptor XML file for the service


makefile 
makefile_debug

Deployment makefiles. Overwrite-protected.

    docs/
index.html

The generated documentation. Use index.html as the entry point to all docs contained in the docs subdirectories.

    include/

Header files, as follows:

      /DayOfWeekExample

Subdirectory by project name


DayOfWeekBindingProxy.h

1. Client proxy class


DayOfWeekBindingSkeleton.h

2. Class that handles messaging


DayOfWeekPortTypeBase.h

3. Base class for the server-side implementation

7.2.3 Using the Client Proxy

The proxy provides a set of five methods for each operation specified in the WSDL description. One pair of methods implements synchronous behavior; the remaining three methods implement asynchronous behavior. To send a message to the Web service, construct an instance of the proxy and invoke either the synchronous or asynchronous method(s) that correspond to the operation. The method returns the values defined in the WSDL file for the response message. (Appendix A describes type mappings for these values.)

The generated sample client implementation uses one of the synchronous methods for all operations, but you can easily change the implementation to create an asynchronous client. The asynchronous <operation-name>Start() method launches a thread for the operation so that the client can continue other processes while waiting for the server to respond. For more information on the client's asynchronous features, see Section 7.3.1, "The Asynchronous Client API.".

The generated header file for the client proxy contains the signatures for the generated service operation methods. The names of the methods that implement the operations in the WSDL file match the WSDL's operation names, with the first letter of the name converted to lower case. Parameter names match the part names in the WSDL file, with an underscore and the direction of the part appended to the name. For example, a part named tickerSymbol which is only used for input will have the name tickerSymbol_in, while an inout part named targetStruct will have the name targetStruct_inout. For details on naming conventions, see Appendix A.

7.2.3.1 Looking at the Code

The sample below shows the public interface for the client proxy, DayOfWeekBindingProxy.h located in the DayofWeekExample\include\DayofWeekExample directory.

The sample is reformatted slightly to fit on the page, and omits include statements, comments, and private members:

//1Derives from base class rwsf::Client
//2The proxy includes three make() convenience methods for obtaining an instance of the proxy.

The first returns a handle to the proxy based on a location parameter specifying the URL of the service. By default, the location is the URL specified in the WSDL file.

//3Returns a handle to the proxy based on a transport parameter specifying the transport for the service. This method is used if a transport type is passed in on the command line, or if the client implementation needs to select a transport dynamically at runtime. Use this method to use a transport other than the default specified in the WSDL.
//4Returns a handle to the DayOfWeekBindingProxyImp body implementation passed as a parameter. (This method is used internally.)
//5Default constructor, copy constructor, destructor.
//6Assignment operator.
//7Sets a property in the transport associated with this client proxy.
//8Declares the first of the two synchronous getDayOfWeek() methods. These methods take a string containing the date, and return the day of week for that date. The second method in the pair differs only in explicitly passing a rwsf::CallInfo object. Use this method if you need to add your own SOAP or transport headers to the message (see Chapter 16, "SOAP and Transport Headers,"), or you want to add some additional message handlers for the outgoing message (see Chapter 15, "SOAP Message Handler SDK,").
//9Declares the first of the two asynchronous getDayOfWeek() 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. See Section 7.3.1, "The Asynchronous Client API," for an explanation of this interface. The second method with the rwsf::CallInfo parameter plays the same role as the corresponding synchronous method.
//10Declares the end method for an asynchronous process, which is used in retrieving the data.

7.2.3.2 Using the Client Proxy

Use the proxy to implement your client application. HydraExpress creates a sample implementation you may use as a framework. This section discusses how to implement the proxy for a synchronous operation. For information on the asynchronous operation, see Section 7.3.1, "The Asynchronous Client API."

First, we'll look at the generated class, and then we'll see how we can easily edit it to implement the getDayofWeek method.

The generated sample implementation below shows the DayOfWeekPortClient.cpp file created by the rwsfgen program and located in the DayOfWeekExample\app\client directory. The sample is not a class, but a source file that includes the proxy header file and a main() function that invokes the proxy's methods.

//1Includes necessary header files.
//2Sample function that invokes the getDayOfWeek operation. The function takes a reference to a DayOfWeekPortClient proxy, creates standard string instances of the input and output variables as well as an instance of rwsf::CallInfo, and calls the getDayOfWeek operation on the proxy. The client generator implements one sample invocation method for each operation. The method uses the synchronous proxy 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 on possible location and transport options when invoking the client at runtime, see Section 7.3.4. (In this case, the location points to the simulated DayOfWeek service that ships with HydraExpress.)

//4Registers the service handlers, naming context, and transports that are available for this message.
//5Obtains a client proxy and ensures that it is valid.
//6Calls the invoke_DayOfWeek() method with 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, you should also catch exceptions derived from RWxmsg.

To create a working client, simply implement the invoke_getDayOfWeek method, replacing the generated code with your own.

In this case we will use the implemented client application DayOfWeekPortClient.cpp provided in the directory <installdir>\tutorials\webservices\DayofWeek.

The code below shows how the shipped file implements the service operation method invoke_getDayofWeek().

Class rwsf::DateTime correctly parses many common date formats. The client uses this class to simplify the process of converting input from the console into the ISO8601 format that the schema requires.

7.2.4 Compiling and Deploying the Client

At this point the client is implemented and ready to compile. The service now needs to be implemented; then both can be built and the service can be deployed to the HydraExpress Agent. Chapter 8 discusses how to implement the service, and Section 8.2.3 discusses building the client and service, and deploying the service.



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.