Dave Burke : Freelance .NET Web Developer specializing in Online Communities

A working XMLRPC Client example

I spent a bit of time googling for XMLRPC.NET client code and never found a good working sample, so here's the complete source in a Winforms app that displays blog titles via XMLRPC using the Metablog API in dotText.  Thanks to Charles Cook for his work in making XML-RPC possible in .NET.  Be sure to read his XMLRPC.NET FAQ for more info.


  [XmlRpcUrl("http://mysite/myblog/services/metablogapi.aspx")]
  public interface IGetRecentPosts
  {
   [XmlRpcMethod("metaWeblog.getRecentPosts")]
   Post[] GetRecentPosts(string blogid, string username, string password, int numberOfPosts);
  }
  

  // TODO: following attribute is a temporary workaround
  [XmlRpcMissingMapping(MappingAction.Ignore)]
   public struct Enclosure
  {
   public int length;
   public string type;
   public string url;
  }

  // TODO: following attribute is a temporary workaround
  [XmlRpcMissingMapping(MappingAction.Ignore)]
   public struct Source
  {
   public string name;
   public string url;
  }

  [XmlRpcMissingMapping(MappingAction.Ignore)]
   public struct Post
  {
   [XmlRpcMissingMapping(MappingAction.Error)]
   [XmlRpcMember(Description="Required when posting.")]
   public DateTime dateCreated;
   [XmlRpcMissingMapping(MappingAction.Error)]
   [XmlRpcMember(Description="Required when posting.")]
   public string description;
   [XmlRpcMissingMapping(MappingAction.Error)]
   [XmlRpcMember(Description="Required when posting.")]
   public string title;

   public string[] categories;
   public Enclosure enclosure;
   public string link;
   public string permalink;
   [XmlRpcMember(
     Description="Not required when posting. Depending on server may "
     + "be either string or integer. "
     + "Use Convert.ToInt32(postid) to treat as integer or "
     + "Convert.ToString(postid) to treat as string")]
   public object postid;      
   public Source source;
   public string userid;
  }

  private void button1_Click(object sender, System.EventArgs e)
  {
   IGetRecentPosts proxy = (IGetRecentPosts)XmlRpcProxyGen.Create(typeof(IGetRecentPosts));
   Post[] post = proxy.GetRecentPosts("69", "myusername", "mypassword", 5);
   for (int i = 0; i < post.Length; i++)
   {
    listBox1.Items.Insert(0, post[i].title);
   }

  }

 }

 

Comments (4) | Post RSS RSS comment feed

Posted on 2/12/2005 11:46:00 PM by Dave Burke
Categories: .NET
Tags:

Related posts

Comments (4) -

2/13/2005 10:56:00 AM Permalink

good for you to post this. Getting the XMLRPC working was the most difficult thing of all for me when I wrote my little blogging app.

Julie Lerman |

2/15/2005 7:53:00 PM Permalink

If you dig around google's cache, you can find an end-to-end sample by Charles Cook that's been out there since about 2001 I guess.

I pretty much ripped off dasBlog's implementation to get PostXING working Smile

Chris Frazier |

2/15/2005 9:44:00 PM Permalink

Wow, Chris, you (like our bud Julie) must have had to spend a lot of quality time with XMLRPC!  She with Blink, and you with PostXING.  It also impresses me how guys like ScottW or Clemens Vasters build a Metablog API into their blog applications.  

Me, I simply scratched the surface to get what I needed to get a GetRecentPosts() call to work.  Once I picked up the Interface approach from Cook's FAQ, the rest was pretty obvious, just duplicate the containers on both ends for the data.

From the little I've learned, XMLRPC seems to be a very robust technology and is yet another fascinating area I was able to stumble into since I started spending my latenights doing dotText mods for fun and profit.  Its been quite a trip, indeed.

Thanks for visiting and for your comments.  

Dave Burke |

2/16/2005 11:18:00 AM Permalink

Heh. I spent more time trying to figure out how to keep the UI responsive when adding/editing/deleting a post Smile

Like I said, I just used the proxy classes from dasBlog, and since that library has MetaWebLog api support for cross-posting, all I had to do was implement it.

It seems tho that their implementation of the Blogger api is a little off - something about capitalization. Never really had the incentive to try it out, but that's what I've been told.

Oddly, xml-rpc is pretty much how I handled webservices in the small amount of time that I had worked with them (I know: bad Chris!) so working with Cook's library wasn't that painful for me at all!

Chris Frazier |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke