You are on page 1of 2

How To Make an XML-RPC Call

By: Scott Watermasysk


Published: 12/11/2002

I never thought I would have gotten as many comments about my little weblog. I was
thinking at one point of making all of TripleASP’s source code available, but I think in the
short run, I am going to put together a small downloadable weblog, so look for that
hopefully by the end of the year.

In the mean time, I know there are a bunch of you writing your own weblog’s at the
moment. In my brief weblogging life time, I have learned a little about XML-RPC. To be
honest, I don’t know too much about it yet, but I did find a pretty nifty library to help
make XML-RPC calls almost a no-brainer. Charles Cook's CookComputing

As a quick example, the downloadable code below will illustrate how to notify
WebLogs.com that you have made an update to your blog.

The WeblogsNotificationProxy

using System;
using CookComputing.XmlRpc;

namespace TripleASP.Components
{
/// <summary>
/// Summary description for WeblogsNotificatinProxy.
/// </summary>
[XmlRpcUrl("http://rpc.weblogs.com/RPC2")]
public class WeblogsNotificatinProxy : XmlRpcClientProtocol
{
public WeblogsNotificatinProxy()
{

private string errormessage = "No Error";


public string ErrorMessage
{
get{return errormessage;}
}

public bool Ping(string name, string url)


{
bool result = false;
try
{
XmlRpcStruct rpcstruct = Notifiy(name,url);
if(rpcstruct.ContainsKey("flerror"))
{
//Weblogs.com return false if there is no error
//I want to return true, indicating a successful notification
result = !(bool)rpcstruct["flerror"];
if(!result)
{
if(rpcstruct.ContainsKey("message"))
{
errormessage = (string)rpcstruct["message"];
}
else
{
errormessage = "Unknown Error";
}
}
}
}
catch(Exception ex)
{
errormessage = "Error: " + ex.Message;
}
return result;

[XmlRpcMethod("weblogUpdates.ping")]
public XmlRpcStruct Notifiy(string name, string url)
{
return (XmlRpcStruct) Invoke("Notifiy",new object[] {name,url});
}
}
}

The Implementation
WeblogsNotificatinProxy wp = new WeblogsNotificatinProxy();
if(wp.Ping("ASP.NET and Me","http://TripleASP.Net/Weblog"))
{
wlMessage.Text = "Weblogs was notified and accepted";
}
else
{
wlMessage.Text = wp.ErrorMessage;
}

Questions? Comments? Contact me at: Contact Copyright © 2001


TripleASP.Net. All rights reserved. Your Privacy

You might also like