Listing 1: Server.cpp

#include "soapH.h"	/* include generated proxy and SOAP support */
#include "ns1.nsmap"
#include "SimpleLibrary.h"

int main()
{
	soap_serve(soap_new());
}


int ns1__shareLegacyData(struct soap *soap, char *&resp)
{
	SimpleLibrary simple;  /* Library containing legacy functions */

	resp = simple.sayHello();

	return SOAP_OK;

}



Listing 2: SimpleLibrary.h

class SimpleLibrary
{
public:
	SimpleLibrary();
	~SimpleLibrary();
	char * sayHello();
};

SimpleLibrary.cpp
/**
 ** This is a simple library example that can be
 ** compiled as either a static (.a) or shared (.so)
 ** library.
 **/

#include "SimpleLibrary.h"


/**
  * A simple C++ constructor
  */
SimpleLibrary::SimpleLibrary()
{

}

/**
  * A simple C++ deconstructor
  */
SimpleLibrary::~SimpleLibrary()
{

}

/**
  * A simple library API, whose functionality will be exposed
  * as a Web Service.
  */
char * SimpleLibrary::sayHello()
{
	return "Hello World";
}



Listing 3: Client.cpp

#include "soapH.h" // obtain the generated stub
#include "ns1.nsmap" // obtain the namespace mapping table

int main()
{
   struct soap soap; // gSOAP runtime environment

   char *resp;

   soap_init(&soap); // initialize runtime environment (only once)

   if (soap_call_ns1__shareLegacyData(&soap, NULL, NULL, resp) == SOAP_OK)
      std::cout << "Server Says = " << resp << std::endl;
   else // an error occurred
      soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream

   soap_destroy(&soap); // delete deserialized class instances (for C++ only)
   soap_end(&soap); // remove deserialized data and clean up
   soap_done(&soap); // detach the gSOAP environment
   return 0;
}



Listing 4: Makefile

WSDL=/home/gsoap-2.7.7/bin/wsdl2h
GSOAP=/home/gsoap-2.7.7/bin/soapcpp2

all:	server client

wsdl:
	$(GSOAP) inc/Server.h 

server: wsdl library
	g++ -o article.cgi soapC.cpp soapServer.cpp src/Server.cpp -I. -I./inc -L/home/gsoap-2.7.7/lib -lgsoap++ -L. -lSimpleLibrary

client: wsdl
	g++ -o client src/Client.cpp soapC.cpp soapClient.cpp -I. -L/home/gsoap-2.7.7/lib -lgsoap++

library:
	g++ -fPIC -g -c -Wall src/SimpleLibrary.cpp -I./inc
	ar cq libSimpleLibrary.a SimpleLibrary.o

clean:
	rm -f *.o *.a *.so article.cgi client.exe *.h *.c *.cpp *.xml *.wsdl *.xsd *.nsmap