Using PocketSOAP from .NET

Note: As the Compact Framework doesn't include COM Interop support, this will only work with the desktop version of .NET, not the Compact Framework version.


Tony Hong (of XMethods fame) sent me this one. First off generate a .NET assembly from the com DLL, to do this, run tlbimp "c:\program files\simonfell\pocketSOAP1.2\psoap32.dll" this should build you a .NET PocketSOAP.dll, then import the PocketSOAP namespace/assembly as normal in C#, e.g.
using PocketSOAP;
using System;

public class test
{
	public static void Main(string[] args)
	{
		Console.WriteLine("Starting C# PocketSOAP for echoString");
		CoEnvelope soap=new CoEnvelope();
		HTTPTransport h=new HTTPTransport();
		soap.MethodName="echoString";
		soap.URI="urn:xmethodsInterop";
		soap.Parameters.Create("inputString", "Hello World", "", null, null);
		h.SOAPAction = "http://soapinterop.org/" ;
		h.Send ( "http://www.whitemesa.net/interop/std", soap.Serialize() );
		soap.Parse(h, null);
		Console.WriteLine(soap.Parameters.get_Item(0).Value);
	}
}
Build the C# as normal remembering to add a reference to the PocketSOAP.dll, e.g.
csc test.cs /r:pocketSOAP.dll
Here's an example I put together that handles arrays.
using PocketSOAP;
using System;

public class test
{
	public static void Main(string[] args)
	{
		Console.WriteLine("Starting C# PocketSOAP for echoStringArray");

		CoEnvelope soap = new CoEnvelope();
		HTTPTransport h = new HTTPTransport();
		soap.MethodName = "echoStringArray";
		soap.URI        = "http://soapinterop.org/";
		
		Object[] sa = new Object[2];
		sa[0] = "hello";
		sa[1] = "goodbye";
		soap.Parameters.Create ( "inputStringArray", sa, "", null,null ) ;

		Console.WriteLine("Encoding style: "+soap.EncodingStyle);
		Console.WriteLine("Method Name : "+soap.MethodName);
		Console.WriteLine("URI : "+soap.URI);

		Console.WriteLine(soap.Serialize());
		h.SOAPAction = "http://soapinterop.org/" ;
		h.Send("http://www.whitemesa.net/interop/std", soap.Serialize());
		soap.Parse(h, null);
		object[] res = (object[])soap.Parameters.get_Item(0).Value;
		Console.WriteLine(res[0]);
		Console.WriteLine(res[1]);
	}
}
And finally, heres another example from Tony that handles arrays and compex types
using System;
using System.Collections;
using PocketSOAP;
 
public class XMListings
{
	public static void Main()
	{
		CoEnvelope soap=new CoEnvelope();
		HTTPTransport h=new HTTPTransport();
		h.SOAPAction="";
		soap.MethodName="getAllSOAPServices";
		soap.URI="urn:xmethodsServicesManager";

		h.Send("http://www.xmethods.net/soap/servlet/rpcrouter", soap.Serialize());		
		soap.Parse(h, null);

		Object[] u = (object[])soap.Parameters.get_Item(0).Value;

		foreach (ISOAPNode x in u)
		{
			Console.WriteLine(x.Nodes.get_ItemByName("name","").Value);
			Console.WriteLine(x.Nodes.get_ItemByName("owner","").Value);
			Console.WriteLine(x.Nodes.get_ItemByName("serverImplementation","").Value);
			Console.WriteLine("-------------------------------");
		}
		return;
	}
}