BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in WSCF/WCF

 
 
Page 2210 of 19542

Programming the MetaWeblog API in .NET/C#

Blogger : Pluralsight Blogs
All posts : All posts by Pluralsight Blogs
Category : WSCF/WCF
Blogged date : 2008 Aug 19

Most modern blogging engines support the MetaWeblog API, which was defined by XML-RPC.com many years ago.  It's become one of the most popular API's for programmatically interacting with blogs because of its simplicity. Even Microsoft's Windows Live Spaces provides support for it.

I wanted to use this API recently to interact with our Community Server implementation so I started searching around for client-side implementations that would be easy to program in C#. I was surprised that I couldn't find a mainstream implementation readily available. So I followed the example on MSDN and built my own MetaWeblog library in C# on top of Cook Computing's XML-RPC.NET library.

Here's what my MetaWeblogClient class looks like (truncated for brevity):

public class MetaWeblogClient : XmlRpcClientProtocol
{
    [XmlRpcMethod("metaWeblog.getRecentPosts")]
    public Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
    {
        return (Post[])this.Invoke("getRecentPosts", 
new object[] { blogid, username, password, numberOfPosts }); } [XmlRpcMethod("metaWeblog.newPost")] public string newPost(string blogid, string username, string password, Post content, bool publish) { return (string)this.Invoke("newPost",
new object[] { blogid, username, password, content, publish }); }
...

With this class, you can simply make method calls like getRecentPosts, newPost, editPost, etc to interact with any blog that supports the MetaWeblog API. You will need to specify that URL to the MetaWeblog endpoint prior to making those method calls. Here's an example:

class Program
{
    static void Main(string[] args)
    {
        MetaWeblogClient blog = new MetaWeblogClient();
        blog.Url = "http://www.pluralsight.com/community/blogs/metablog.ashx";

        // here's how you post a new entry...
        Post newPost = new Post();
        newPost.dateCreated = DateTime.Now;
        newPost.title = "Test post from Metablog Api";
        newPost.description = "This is the body of the post";
        newPost.categories = new string[] { "WCF", "WF" };
        blog.newPost("blogid", "username", "password", newPost, true);

        // here's how you retrieve the most recent entries...
        Post[] posts = blog.getRecentPosts("blogid", "username", "password", 5);
        foreach (Post post in posts)
            Console.WriteLine(post.title);
    }
}

The code turns out to be wonderfully simple. So if you find yourself in the same boat as me, looking for a MetaWeblog C# implementation, feel free to download my library here. Hopefully it will save you a little bit of time!


Read comments or post a reply to : Programming the MetaWeblog API in .NET/C#
Page 2210 of 19542

Newest posts
 

    Email TopXML