Cook Computing

XML-RPC Blogging APIs

February 16, 2003 Written by Charles Cook

I've come down with a cold this weekend and didn't get much done. I managed to do some testing of some sample interface definitions I'm working on for inclusion in the XML-RPC.NET FAQ. The interfaces are for the Blogger and MetaWeblog APIs, and will make writing .NET blogging clients easier. For example, assuming you've included the assembly containing the CookComputing.Blogger assembly, you just need to create a proxy via the code-generating XmlRpcProxyGen class, set the required url, and then make any of the Blogger API calls on the interface. For example, to retrieve the list of categories available for a blog:


using CookComputing.Blogger;
 
IBlogger  proxy = (IBlogger)XmlRpcProxyGen.Create(typeof(IBlogger));
XmlRpcClientProtocol xpc = (XmlRpcClientProtocol)proxy;
xpc.Url = "http://EraBlog.NET/rpc/v1.1/erablog.xmlrpc";
Blogger.Category[] categories  
  = proxy.getCategories("1234", "MyBlog", "pwd");

The interface can also be used to implement the server side of these APIs. In this case you derive the service class from the XmlRpcService class and the required interface(s), and then implement the interface methods in this derived class.

While testing a Movable Type server I noticed that the XML-RPC fault response is incorrectly implemented:


<?xml version="1.0" encoding="UTF-8"?> 
<methodResponse>
  <fault>
    <value>
      <struct>
        <member>
          <name>faultString</name>
          <value><string>Invalid login</string></value>
        </member>
        <member>
          <name>faultCode</name>
            <value><string>Server</string></value>
        </member>
      </struct>
    </value>
  </fault>
</methodResponse>

Of course, the fault code should be an integer type. I was pleased to note that the parse stack feature I recently implemented in the deserializer worked successfully:


"fault response contains string value where integer expected 
[fault response : struct mapped to type Fault : member 
faultCode mapped to type Int32]"

Fault is the .NET type which the fault response is mapped onto:


struct Fault
{
  public int faultCode;
  public string faultString;
}

This is a simple example but in general the parse stack allows diagnostics to be produced for nested types within structs and arrays. Having seem some of the very complex responses handled by some users of the library, this can be very helpful where the XML-RPC - .NET mapping of types is incorrect, for example where the response is different to what was documented.