Building a SOAP Server: Magic Squares

This example shows you how to create a "magic square" server. This example demonstrates the use of a multi-dimensional dynamic array to hold the magic square implemented by a matrix class.

The server is installed as a CGI application.

Step 1: Write the Main Program

We wrote an example client program for you: click here and select "File - Save As" from your browser's menu.

Step 2: Generate the SOAP Stub and Skeleton Routines

Before you can compile and run your  program, you must generate stub and skeleton routines 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 names of the SOAP methods (with optional namespaces) and the data structures given as C/C++ declarations. For this example, the input to the compiler is a specification of the matrix class for the magic square (a matrix with rows of vectors) and the RPC function:
class vector
{ public:
  int *__ptr;
  int __size;
  vector(int n);
  void resize(int n);
  int& operator[](int i);
class matrix
{ public:
  vector *__ptr;
  int __size;
  matrix(int n, int m);
  void resize(int n, int m);
  vector& operator[](int i);
int ns1__magic(int rank, matrix *result);
This is sufficient to generate all the C/C++ sources necessary to build your service!

To generate the stub and skeleton source codes for the service, 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 Server App

Compile the sources. For example, in Linux the command to compile would be:
g++ -o magicserver.cgi magicserver.cpp soapC.cpp soapServer.cpp stdsoap2.cpp

Step 4: Try it Out

Create a client for this server. See the magic square client example.