Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web service client library for C++

I'd like to implement a web service client for a project on Windows. I want to get web service info, soap request and soap response. I need a C++ library that I can use for these purposes (not wsdlpull).

Requirements:

  • should be a C++ library
  • can be used to access any SOAP web service (so I can pass the URL, the web service name, the web service method and all the arguments as arguments to a function call)
  • can query the web service for its WSDL and return me the available method names, arguments of the methods and their data types
  • simple doucmentation

To be more specific: library should have simple calls like this for getting web service information

invoker.getOperations(operations);

outputXml += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
outputXml += "<webService";
outputXml += " name=\"" + GetServiceName(&invoker) + "\"";
outputXml += ">\n";
outputXml += "\t<webMethods>\n";

Thanks.

like image 455
csk Avatar asked Feb 01 '12 14:02

csk


1 Answers

The industry standard for C/C++ web services is gsoap. http://www.cs.fsu.edu/~engelen/soap.html

Provides mapping XML Schema to C/C++ with wsdl2h. It has good documentation and a lot of samples in the package. Doc can be found also online. You can easily port your code in many OSs (linux, windows etc)

Simpe example to add to number via a web service (invocation code)

#include "soapH.h"
#include "calc.nsmap"
main()
{
   struct soap *soap = soap_new();
   double result;
   if (soap_call_ns__add(soap, 1.0, 2.0, &result) == SOAP_OK)
      printf("The sum of 1.0 and 2.0 is %lg\n", result);
   else
      soap_print_fault(soap, stderr);
   soap_end(soap);
   soap_free(soap);
}

With gsoap you do the job in two steps

  1. First create stubs (like wsdl2java) from the WSDL
  2. Then you call the stubs with your objects

Also excellent framework if you want to create your service (act as a server, not only client code)

like image 89
cateof Avatar answered Sep 29 '22 03:09

cateof