A Good C++ Library for SOAP
Check out Apache Axis. That is my all times favorite SOAP implementation. It's SOAP done right! Exists for C++ and Java.
http://ws.apache.org/axis/
And in best traditions of Apache Foundation, it is FREE and OPENSOURCE.
So, enjoy!
Which linux C/C++ SOAP library? Need very lightweight recommendations
Well, if it is that simple, you can use a low level HTTP lib like libcurl and code your request by hand or using an xml lib.
I do not know simplesoap. I've just browsed the site, it seems adequate ^^
I agree with you on gSoap :)
My 2 cents.
SOAP library in C
Take a look at this blog entry. I know it's C++, but I have had good results with Apache's AXIS. If you can use a C++ compiler, you can wrap around a C library to your generated classes.
Generic WebService (SOAP) client library for C++
I found a solution using on-the-fly-generated assemblies (which I couldn't get working the previous time). Starting point is http://refact.blogspot.com/2007_05_01_archive.html.
E.g. This is the code to use the PeriodicTable web service:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web;
using System.Web.Services;
using System.Web.Services.Description;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Xml.Serialization;
using System.IO;
using System.Reflection;
namespace GenericSoapClient
{
class Program
{
static void method1()
{
Uri uri = new Uri("http://www.webservicex.net/periodictable.asmx?WSDL");
WebRequest webRequest = WebRequest.Create(uri);
System.IO.Stream requestStream = webRequest.GetResponse().GetResponseStream();
// Get a WSDL
ServiceDescription sd = ServiceDescription.Read(requestStream);
string sdName = sd.Services[0].Name;
// Initialize a service description servImport
ServiceDescriptionImporter servImport = new ServiceDescriptionImporter();
servImport.AddServiceDescription(sd, String.Empty, String.Empty);
servImport.ProtocolName = "Soap";
servImport.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties;
CodeNamespace nameSpace = new CodeNamespace();
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
codeCompileUnit.Namespaces.Add(nameSpace);
// Set Warnings
ServiceDescriptionImportWarnings warnings = servImport.Import(nameSpace, codeCompileUnit);
if (warnings == 0)
{
StringWriter stringWriter =
new StringWriter(System.Globalization.CultureInfo.CurrentCulture);
Microsoft.CSharp.CSharpCodeProvider prov =
new Microsoft.CSharp.CSharpCodeProvider();
prov.GenerateCodeFromNamespace(nameSpace,
stringWriter,
new CodeGeneratorOptions());
string[] assemblyReferences =
new string[2] { "System.Web.Services.dll", "System.Xml.dll" };
CompilerParameters param = new CompilerParameters(assemblyReferences);
param.GenerateExecutable = false;
param.GenerateInMemory = true;
param.TreatWarningsAsErrors = false;
param.WarningLevel = 4;
CompilerResults results = new CompilerResults(new TempFileCollection());
results = prov.CompileAssemblyFromDom(param, codeCompileUnit);
Assembly assembly = results.CompiledAssembly;
Type service = assembly.GetType(sdName);
//MethodInfo[] methodInfo = service.GetMethods();
List<string> methods = new List<string>();
// only find methods of this object type (the one we generated)
// we don't want inherited members (this type inherited from SoapHttpClientProtocol)
foreach (MethodInfo minfo in service.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
{
methods.Add(minfo.Name);
Console.WriteLine (minfo.Name + " returns " + minfo.ReturnType.ToString());
ParameterInfo[] parameters = minfo.GetParameters();
foreach (ParameterInfo pinfo in parameters)
{
Console.WriteLine(" " + pinfo.Name + " " + pinfo.ParameterType.ToString());
}
}
// Create instance of created web service client proxy
object obj = assembly.CreateInstance(sdName);
Type type = obj.GetType();
object[] args0 = new object[] { };
string result0 = (string)type.InvokeMember(methods[0], BindingFlags.InvokeMethod, null, obj, args0);
Console.WriteLine(result0);
object[] args1 = new object[] { "Oxygen" };
string result1 = (string)type.InvokeMember(methods[1], BindingFlags.InvokeMethod, null, obj, args1);
Console.WriteLine(result1);
}
}
}
}
In this code I explicitly use methods[0]
and methods[1]
but in reality you would check the method names of course. In this example I get the names of all elements in the periodic table, then get the atomic weight of oxygen.
This example does not yet contain logic to support a proxy. I still need to add this, but for the moment, it solves my biggest problem, namely, having a generic SOAP client.
EDIT:
I know this code is C# and I was originally asking for a C++ solution, but this code proves that it can work in a .NET environment (which I can still use in limited parts of my application), and I will probably rewrite this code into C++/.NET, which solves my problem.
Best XML Parser with SOAP Request/Response Support
I think it is a good question.
First: if you use xml/soap/wsdl based web services, you have probably a really highlevel project, and thus even the c++ isn't really sure an optimal choice. I think it is very unlinkely, if you want to develop a real, working software in C, which makes soap services. IMHO you could think about java.
Second: xml and soap/wsdl are two different things, although soap uses xml for communication and the interface description (wsdl) is xml, too.
For xml handling, I suggest you could use libxml++ .
For SOAP, there is more library, but most of them isn't enough good for me to name them. Try each after the other, and sometimes you will have luck. :-)
Both libs have small footprint - they are relative complex, but don't need a legion of another libraries.
Looking for a portable SOAP Client C++ Library
the library that comes to mind to handle SOAP in C++ is gsoap I think it matches your requirements. If I remember correctly some of their tools are not open-sourced if you use them to produce non open-source code. Check the license ...
Great toolkit. Worked very well for me some times ago ...
my2c
EDIT: As said in comment you have tools to generate code from WSDL description. That's those tools that you can not use if you do not want your code to be GPL'ed ^^
Related Topics
Forward Declaration VS Include
Under What Circumstances Are C++ Destructors Not Going to Be Called
Load an Pem Encoded X.509 Certificate into Windows Cryptoapi
Using 'Const' in Class's Functions
How Does C++ Exception Handling Translate to MAChine Code
Qt/Qml:Send Qimage from C++ to Qml and Display the Qimage on Gui
Localtime VS Localtime_S and Appropriate Input Arguments
How to Use an Enum Value in a Switch Statement in C++
Double-Checked Lock Singleton in C++11
Maximum Number of Parameters in Function Declaration
Is Assignment Operator '=' Atomic
How to Install/Configure Opencv3.2.0 with C++, Visual Studio 2017
Portable Compare and Swap (Atomic Operations) C/C++ Library
Why Can't I Store References in a 'Std::Map' in C++
Recursive Lambda Functions in C++14
What Is the Performance Implication of Converting to Bool in C++