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

Using a configurable MetaBlog Url param with the XmlRpcUrl Attribute

This is more of a "how to move on" than a "how to" post.  I think it will be helpful though, considering I read page after page about the XmlRpcUrl attribute parameter and every code example (and there were a lot of them) read [XmlRpcUrl("SomeHardCodedMetaBlogUrl")]. 

I wrote a Blog Migration app that uses XMLRPC and the MetaBlog API to retrieve posts from one blog and post them to another blog.  The app does more than that, but the description serves our purposes here. 

To retrieve posts from a source blog, an interface is created to that site's GetRecentPosts MetaBlog API method, then called in the app when required.  The same process occurs with the destination blog NewPost method.  I needed a way to use a Windows Forms app.config value as the MetaBlog Url parameter for the source and destination blogs.  Surely this had been done before, but maybe not.

[XmlRpcUrl("http://dbvt.com/blogs/metablog.ashx")]  <-- Need to pull URL from app.config
public interface IGetRecentPosts
{
    [XmlRpcMethod("metaWeblog.getRecentPosts")]
    SourcePost[] GetRecentPosts(string blogid, string username, string password,
        int numberOfPosts);
}

Charles Cook is a Hero of Our Time and we are all in his debt for his work in XMLRPC. Cook's work has made it possible for us to do many of the remote functions that we take forgranted.  While trying to figure out how I was going to pass a dynamically generated parameter to XmlRpcUrl, it dawned on me that Charles also provides the source for the .NET XMLRPC libraries.  If I couldn't bang it out in the end-point application, I'd go to the XMLRPC library source.  My app's logic requires a source and destination metablog url, so I changed the GetEffectiveUrl() method in the CookComputing.XmlRpc.XmlRpcClientProtocol to handle the literal "source" and "destination" strings.


string GetEffectiveUrl(object clientObj)
{

System.Configuration.AppSettingsReader appReader =
       new System.Configuration.AppSettingsReader();

if (Url == "" || Url == null)
{
Attribute urlAttr = Attribute.GetCustomAttribute(type, typeof(XmlRpcUrlAttribute));
if (urlAttr != null)
{
XmlRpcUrlAttribute xrsAttr = urlAttr as XmlRpcUrlAttribute;
if (xrsAttr.Uri == "source")
{
    useUrl = (string)appReader.GetValue("SourceMetaBlogAPIUrl", typeof(string));
}
else if (xrsAttr.Uri == "destination")
{
   useUrl = (string)appReader.GetValue("DestinationMetaBlogAPIUrl", typeof(string));
}
else
{
   useUrl = xrsAttr.Uri;
}
}

}


I'm confident other devs reading this would have a more elegant solution, and you know me well enough to know that I'd welcome those suggestions with open arms.  But this does the job and I'm moving on.

Comments (0) | Post RSS RSS comment feed

Posted on 11/25/2006 3:44:07 PM by Dave Burke
Categories: .NET
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke