Currency Exchange Rate Example

This example shows you how to create a client that will interact with Xmethod's Currency Exchange Rate service to provide you with up to date information on the exchange rates between countries.

The client program will accept the names of two countries from the command line and will display the current exchange rate.

Step 1: Write the Main Program

Save the program source below to a local file (e.g. exchange.cpp). To do this, you can also click here and select "File - Save As" from your browser's menu.

Step 2: Generate the SOAP Stub Routines

Before you can compile and run your delayed stock quote program, you must generate C/C++ sources using our stub compiler. The generated sources take care of the SOAP serialization and deserialization of the data required to access the SOAP service.

The input to our stub compiler is a specification of the name of the SOAP method (with it's optional namespace) and the data structures given as C/C++ declarations. For this example, the input to the compiler is just a function prototype:
int ns1__getRate(char *country1, char *country2, float *result);
This is sufficient to generate all the C/C++ sources necessary to build the client application!

The method name is "getRate" with namespace identifier "ns1" and it has two input string parameters "country1" and "country2" and one output float parameter "result" passed by reference. Note that the paramter names correspond to the request and response XML schema definitions for the getRate method as found on the Xmethods web site.

To generate the sources, click here to use our SOAP Stub Compiler. This will produce a web page containing the C/C++ sources for:

You need to save these sources to your local drive under the file names as indicated.

Two files are not generated but are required to build your application: stdsoap2.h and stdsoap2.cpp. Save these files to your local drive too.

Step 3: Compiling Your Client App

Compile the sources. For example, in Unix/Linux the command to compile would be:
g++ -o exchange exchange.cpp soapC.cpp soapClient.cpp stdsoap2.cpp

Step 4: Try it Out

Execute the command "exchange us uk" which returns with
Exhange rate us to uk is 0.706964
(as of 8/8/2001.)

For a list of country names, see Currency Exchange Rate.