Please Note: This entry is an archived entry from my previous weblog. No new comments may be posted. Also, as of May 2005, I have left Microsoft. I am still happy to respond to any questions or comments about this article, but as I am no longer on the Visual Studio team, I may not be able to provide any helpful answers.

February 23, 2003

[permalink] XrpGen and a little luck

"The time has come," the Walrus said, "to release a bit of code."  Okay, so I've been banging around doing some work with the XML-RPC.NET libaries, in an attempt to write some kind of nice Winforms frontend to Movable Type.  I got rather sidetracked on this quest, however, and wound up working on some stuff to automatically generate XML-RPC proxy classes for a given API's interface.

Charles Cook, the the master behind the XML-RPC.NET work, has been thinking about blogging APIs as well, and I think we've hit many of the same roadblocks.  So instead of dealing with client UI work, I decided it was much more interesting plugging away at some lower-level stuff.  One of the big problems with the design of XML-RPC (and there is more than one, to be sure) is the lack of useful introspection APIs.  This makes developing a tool like .NET's "wsdl.exe" tool pretty much impossible.  Fortunately, the XML-RPC.NET libraries make using XML-RPC very easy. Charles' libraries are quite clever, and they will let you take an interface definition and create a proxy assembly at runtime that will let you consume a service whose API matches that interface.  Unfortunately, this is sometimes an undesirable solution for a few reasons, not the least of which is that the Reflection.Emit facilities require significant security permissions. 

I don't pretend to solve the problem of the lack of good introspection in XML-RPC, but I've created a tool that might be helpful in many situations.  The tool, which I've named XrpGen (I suppose "zurp-gen") uses CodeDOM instead of Reflection.Emit to create source code for a proxy class, instead of emitting it at runtime as a consumable assembly.  Basically, you can use a have an interface like this:

[XmlRpcUrl("http://www.foo.bar/blog/api.cgi")]
public interface ITest
{
        [XmlRpcMethod("test.Bar")]
        string Bar(bool b, DateTime d);
        ...
}       
 
And execute a command like this:
xrpgen.exe -input:ITest.cs -output:ProxyTest.cs -interface:Test.ITest 
    -ref:CookComputing.XmlRpc.dll
And get a proxy class that looks a little like this:
  
[XmlRpcUrlAttribute("http://www.foo.bar/blog/api.cgi")]
public sealed class TestRpcProxy : XmlRpcClientProtocol, ITest
{
    public TestRpcProxy()
    {
    }
    [XmlRpcMethodAttribute("test.Bar")]
    public string Bar(bool b, System.DateTime d)
    {
        object xrtTemp = null;
        string xrtReturn = null;
        object[] xrtArray = new object[] { b, d };
        xrtTemp = this.Invoke("Bar", xrtArray);
       xrtReturn = ((string)(xrtTemp));
        return xrtReturn;
    }
... }

This is basically an extension of the work that Charles and I have both mentioned before, but this is the first time I've made the code and associated tools available publicly.  To make future integration of my work into the regular distribution as easy as possible, I'm releasing all the code under the MIT License

You can get the full source for the XrpGen tool and the XmlRpcProxyCodeGen class here: [ xrpgen-1-0-1.zip ]  I don't promise that it will work properly, but it works for me.  (Of course, my code requires the main XML-RPC.NET libraries.)  I'll post fixes and updates as I make them.  If you run into any bugs or have suggestions for improvements, please drop me a line.

(It's probably worth noting that I posted this using a really minimal Movable Type client I wrote that uses a proxy class generated by XrpGen.  So it really does work, a little.)

< Geekness > Posted at February 23, 2003 08:44 AM

Comments
  1. XrpGen
    Excerpt: Joe Bork has released his XrpGen tool. This is based on his XmlRpcProxyCodeGen class I mentioned recently. It takes a
    Trackback from: Cook Computing at February 24, 2003 12:39 AM