Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
HydraExpress Web Service Development Guide

4.3 Add a Special SOAP Header

HydraExpress offers full support for SOAP and transport headers, and processes all required headers as well as any number of custom header elements. In this section, we extend the HelloWorld example further to create an appropriate response based on a provided locale.

4.3.1 Add the SOAP Header to the Generated Client

The first step is to modify the generated client implementation by adding a SOAP header element to a rwsf::CallInfo object. The call to the client proxy sayHello() service operation method passes in the rwsf::CallInfo object. The code that assembles the request message adds the SOAP header elements to the SOAP message header as well as adding the transport header elements to the transport header.


This example manipulates the SOAP header directly in the client and server implementation code, for the sake of simplicity. A better design would be to create message handlers on the client and server to do this work outside of the business logic. This design would allow future changes without having to recompile and redeploy the service. For information on creating custom message handlers, see Chapter 14, "SOAP Message Handlers."

Open the generated client sample implementation, GreetingPortClient.cpp, located in the Extended\app\client directory.

Here's the generated service operation method, as yet unimplemented. We'll add the new code to this method.

Replace the above code for the service operation method with the following implementation to add a SOAP header element to the request message:

//1

Instantiates a rwsf::CallInfo object. This class contains data about a message, including session or transaction data, SOAP headers, or transport headers.

//2

Adds a request SOAP header element named LocaleHeader, in a namespace with the prefix locale, whose value is the literal string "es_MX", representing Mexican Spanish. In a real application, the locale would be obtained from the system's locale data so the application would work correctly on any machine. As suggested earlier, this could actually be handled in a message handler rather than in the implementation code.

//3

Calls the sayHello() method in the proxy, passing the rwsf::CallInfo object containing the header data.

Save and close the file.

4.3.2 Edit the Server-Side Code to Return a Response Based on the Header

On the server-side, the server code extracts the locale information from the SOAP header and uses it to create an appropriate response for the locale.

Open the generated server sample implementation GreetingPortTypeImp.cpp located in your Extended\app\server directory. Let's look at the generated sample service operation method:

To implement the method to extract the locale information from the client's SOAP header, replace the code above with the implementation below:

//1

Extracts the value for the locale contained in the SOAP header from the client.

//2

Logic to determine the correct response. Of course, a real application would have some kind of map from locale value to appropriate responses.

//3

Returns the appropriate response.

Save and close the file.



Previous fileTop of DocumentContentsNo linkNext 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.
Provide feedback to Rogue Wave about its documentation.