Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a solution using on-the-fly-generated assemblies (which I couldn't get working the previous time). Starting point is <a href="http://refact.blogspot.com/2007_05_01_archive.html" rel="nofollow">http://refact.blogspot.com/2007_05_01_archive.html</a>.</p> <p>E.g. This is the code to use the PeriodicTable web service:</p> <pre><code>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&lt;string&gt; methods = new List&lt;string&gt;(); // 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); } } } } </code></pre> <p>In this code I explicitly use <code>methods[0]</code> and <code>methods[1]</code> 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.</p> <p>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.</p> <p><strong>EDIT:</strong></p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload