Nuno
Nuno

Reputation: 1940

how to make a soap call in c++

I'm trying to figure out what is the best way of doing a c++ soap client that is independent of the wsdl.

What i need is something like to only know the name of the function and the list of parameters to send and send it and receive the soap response or something like this (i know that this is not as simple as it).

My idea is to do something like: SOAP Request and Response Read from and to file using libcurl - C or http://www.cplusplus.com/forum/general/16225/

Can you point me to the best way of doing this, or the best way is to use a library like gSoap and execute in the c++ code the c++ method of the classes that the gSoap generates?

Thanks

Upvotes: 2

Views: 8837

Answers (2)

rustyx
rustyx

Reputation: 85531

Beware that gSOAP is GPL-licensed. A less restrictive alternative is Axis2/C++.

With Axis2/C++ you can generate stubs from a WSDL and use the generated classes to invoke the web service in your code

Generate stubs (yes Java, but this is a one-time action):

java org.apache.axis.wsdl.wsdl2ws.WSDL2Ws Calculator.wsdl -lc++ -sclient

Then use:

#include "Calculator.h" 
#include <stdio.h> 
int main() 
{ 
  Calculator c; 
  int intOut; 
  c.add(20, 40, intOut); 
  printf("result is = %d\n", intOut); 
  return 0; 
}

More details here

Upvotes: 5

Jan Hudec
Jan Hudec

Reputation: 76376

Depending on what you are up to. If you need single request somewhere, curl (like you linked in the question) is appropriate. C++ contains C, so for once you don't really need C++ interface, though it would be nicer.

But if you need to do some serious work over SOAP, I would definitely recommend using gSOAP or similar library. XML is rather tedious to work with. Serialization/deserialization is the easiest way to deal with it and C++ being statically typed, the serialization code has to be generated there from the schema. Which is just what gSOAP does. So I don't think there is an easier way than gSOAP.

Even if you don't have WSDL for it, I think it's easier to declare the methods you need in WSDL and generate appropriate serialization code from it than having to deal with XML by hand. In more dynamic languages the serialization/deserialization can be generated at runtime, but C++ does not allow that.

Upvotes: 3

Related Questions