ATNF Astronomy Web Services
  Navigation  


 
 
 
 
 

Building a C++ client using gSOAP

When you create a web service in gSOAP, it is easy to create a client in parallel. gSOAP is a very good package, which appears more complicated to use initially than it actually is. Most of the hard work in done for you with a couple of scripts, and pretty much all you have to do is fill in the actual functionality you require in the service and the client.

C++ probably wouldn't be my first choice to write a client in, but it isn't too much harder than the Python client - particularly given the excellent documentation available. Once you have gSOAP installed, the process is as follows.

Accessing the service using WSDL

Firstly you must obtain the publicly available WSDL file and run the WSDL parser, which creates a C++ (or C) header file:

 phoenix% wsdl2h -o quanta.h quanta.wsdl  

You then run the gSOAP Stub and Skeleton compiler on the header file (you may have to copy some of the standard header files - like stl.h - from the gSOAP installation into your current directory):

 phoenix% soapcpp2 quanta.h 

The header file allows you to work out what methods are available and how they should be called. Firstly there is the general information about the service:

 // Service quanta : gSOAP 2.6.0 generated service definition //gsoap ns1 service name:       quanta  //gsoap ns1 service type:       quanta  //gsoap ns1 service port:       http://phoenix:18080/  //gsoap ns1 service namespace:  urn:atnf-aips-quanta  

Then there is a section which lists the available methods:

 /* Service quanta operations:   ns1__has_USCOREunit   ns1__has_USCOREconstant   ns1__has_USCOREprefix   ns1__list_USCOREunits   ns1__list_USCOREprefixes   ns1__can_USCOREconvert   ns1__converts   ns1__convertf   ns1__convert_USCOREtobase   ns1__convert_USCOREtable */ 

and a section giving the interface for each method:

 // Operation convert_USCOREtobase :  // Service definition of function ns1__convert_USCOREtobase int ns1__convert_USCOREtobase(std::string* quantity,   struct ns1__convert_USCOREtobaseResponse {     std::string* result;   } & ); 

From this information we can write a client program to access the convert_tobase function:

 #include  #include   #include "soapH.h" #include "quanta.nsmap"                                                                                  using namespace std;  int main(int argc, char **argv){   struct soap soap;   string result   string input = argv[1]   string endpoint = "http://phoenix:18080/quanta"   struct ns1__convert_USCOREtobaseResponse response;    soap_init(&soap);   if(soap_call_ns1__convert_USCOREtobase(&soap, endpoint, "", &input, response))     soap_print_fault(&soap, stderr);   cout 

which when compiled and run gives the expected results

 phoenix% g++ soapC.cpp soapClient.cpp stdsoap2.cpp client.cc -o client phoenix% ./client '10km/s' 10000 m/s 

In this explanation I have skipped over some details - mainly to do with installation and compiling. These are discussed further on the WIKI page.

 

Webmaster
ASKAP
Public