Microsoft Windows Live Writer (Beta 2) is by far and away one of the coolest tools I've used in a long time.  Since I created Minima, I was using my own extremely lame WPF app to do all my posting and it made posting a bore.  I've been meaning to put some time into making a more interesting WPF app, but instead Windows Live Writer saved the day.  With this thing I can post new entries, save drafts, set labels, as well as view and edit previous entries.

 Having said all that, setting it up wasn't that easy.  Well, the setup was simple, but figuring out what to setup wasn't.  I kept thinking that there was some .NET interface you had to implement, because the documentation kept talking about it's API and gave COM and .NET examples.  Well as it turns out, all you have to do is implement a well known blogging API and point WLW to it!  In my case, I chose the Metaweblog API.

Setting this API was actually rather simple, though it took some experimentation at first as I've never worked with the API at first.  Also, this API uses XML-RPC calls and at first and, at first, I figured I would have to write the XML listener and all XML messages manually.  It turns out that there's a nice API called XML-RPC.NET.  You set this up similar to how you setup a WCF service: via interfaces.

Here's the basic idea behind the XML-RPC.NET API:

[XmlRpcService(Name = "Minima API", AutoDocumentation = true)]
[XmlRpcUrl("http://www.netfxharmonics.com/xml-rpc/")]

public class XmlRpcApi : XmlRpcService
{
    [XmlRpcMethod("blogger.getUsersBlogs")]
    public BlogInfo[] GetUsersBlogs(String key, String username, String password) {
        // Stuff goes here
    }
}

You just set two class-level attributes and then set a method-level on each method.  Then you expose this class as an HttpHandler as the XmlRpcService class this class is inheriting from actually implements the IHttpHandler interface, which is rather convenient.

How did I know what methods I had to implement?  Well, the Metaweblog API "specification" is NOT a real specification, it's just an article that only mentions parts of it.  Also, XML-RPC.NET doesn't seem to have any useful tracing abilities, so that was out.  After a while though, I just found someone else's web site that implements the Metaweblog API and looked their API documentation (you can just look at the sample API below).  It turns out that to use the Metaweblog API means you will be using parts of the Blogger API as well.  Interesting...

Being a minimalist though, I wasn't about to implement ALL functionality.  So I setup an ASPX page that took the Request.InputStream, pointed WLW at the page, and when WLW did a request I got an e-mail from my ASPX page.  When I saw that WLW was calling a specific function, I implemented that specific one.  Of course I also had to implement specific data structures as well.  Really though, all you have to do is use XML-RPC.NET to implement the functions it wants and give it the structures in the Metaweblog API (as you can see in the sample API below) and you're done.

[As a side note, if you aren't familiar with what I mean by accessing the Request.InputStream steam, this stream contains the information that comes to the ASPX page in the POST portion of the HTTP request.  You will often access this when you are creating manual XML services (see my XmlHttp Interop article below for an example).  Here is an example of getting the input stream:

Byte[] buffer = new Byte[context.Request.InputStream.Length];
context.Request.InputStream.Read(buffer, 0, (Int32)context.Request.InputStream.Length);
String postData = ASCIIEncoding.UTF8.GetString(buffer);

You could use something like this to view what information is being sent from WLW.]

In my debugging I found that WLW has a tremendous number of extremely weird bugs.  For example, one of the structures I needed to implement was a structure called "Post" (I'm using the term structure, but it's just XML over the wire and it's a class in my API-- not a struct).  However, WLW would give me errors if some of the fields were null and would give me a different error if they weren't null, but even then, it was only one some functions.  So I had to create two versions of "Post".  One called "Post" which only had a few members, and the other called "FullPost", which had everything.  Strange.  Oh well... I've seen worst (ever use Internet Explorer?)

In the end though, WLW was talking seamlessly with my API.  I was really, really dreading making a better blog client as that felt like such a waste of time (and there was NO way I was going to use a web client-- WPF RULES!). Windows Live Writer (Beta 2) has already been a great help for me in the past week. Not just WLW itself though, but also some of the great plugins you can use with it. For example, in this write-up, I used a Visual Studio pasting plugin to allow me to copy from VS2005 and paste here to get fancy color syntax. Cool!

Related Links

}