Introduction to gSOAP library

Introduction to gSOAP library


 gSOAP  kit allows C++ developers to focus on app logic instead of infrastructure, resulting in reduced development time, fewer bugs, and faster time to market.

It automatically generate C and C++ source code to consume and deploy XML and JSON REST APIs and SOAP/XML Web service APIs and serialize C and C++ data in XML using gSOAP XML data bindings(XML data binding means that your XML data is simply represented as C/C++ data.)

 In general,
 gSOAP offers a type-safe approach to develop XML applications that has proven to be quicker to develop(by auto   coding) , more reliable (by auto-generation of XML test messages and warnings), and higher performing (by efficient   serializers and XML parsers generated in C/C++), compared to DOM and SAX libraries.


 For using gSOAP for building web service application, we will need few tools beforehand::
1.  a C++ compiler.
2. The gSOAP software from Select the gSOAP            toolkit commercial edition to  download from the site.
3. OpenSSL  and the Zlib libraries to enable SSL and compression.  
4. gSOAP 'stdsoap2' (stdsoap2.exe for windows) stub and skeleton compiler available in binary form in      the platform-specific distribution packages.
5.'stdsoap2.cpp' and 'stdsoap2.h' files containing the runtime library to be linked with your Web                 Services applications.

Sample Code for example.
   Here is an example of basic program for those getting started in gSOAP.

    Display "Welcome-Name" greeting using SOAP.

   We need to implement a welcome API that accepts a name returns the greeting.

   We use the gSOAP XML data binding for C++( as the API uses XML )which makes our code easier to use. 

   The "welcome"API is declared as an (XML namespace qualified with ns_) function in our  welcome.h header file.

   int ns__welcome(std::string name,std::string &greeting);  //welcome.h header

  Now we generate the API source code form this header file using the gSOAP soapcpp2 CLI:
   soapcpp2 welcome.h

 This generates the source code we need for our SOAP/XML API.
 Now we implement our API functionality before we can build and deploy our API.  
 We need to define main() and add a function ns___welcome() ::

// welcome.cpp
#include "soapH.h"  // including the source code header
#include "ns.nsmap" // including XML namespace
int main()
  return soap_serve(soap_new());
int ns__welcome(struct soap *soap, std::string name, std::string& greeting)
  greeting = "Welcome" + name;
  return SOAP_OK;

We compile welcome.cpp  with the generated soapC.cpp and soapServer.cpp code and the stdsoap2.cpp library:

We can also compile it with fast CGI which significantly improves the performances of CGI SERVICES::

 c++ -DWITH_FASTCGI -o calcserver.cgi calcserver.cpp soapC.cpp soapcalcService.cpp stdsoap2.cpp