Last DotNetJunkies post

For the last couple of years I've been conscious of the fact that my online efforts are spread over the web with little rhyme or reason.

It seems inherently silly to have a personal web site and have my actual blog hosted elsewhere.
So, in order to move closer to providing a One-Stop Shop For All Your Kevin Daly-related Needs (er...), and also to um,  sort-of-you-know-what-I-mean "unify the brand", I've created a blog on my web site at http://www.kevdaly.co.nz/weblog.
It also gives me complete control over content and format, so from now on everything is my fault.
That is where I'll be posting in future (I've copied some past posts over to the new blog for convenience. But I won't be doing that with this one because that would be stupid, eh).

I'd like to give a big "thank you" to Donny and the Dotnetjunkies team for hosting my ramblings for the past few years, it's much appreciated.

 

That's all Ladies and Gentlemen.

More BlogApi fixes....All done now I think

Anyone who's interested can get the latest version here.

I've been dogfooding this one with Windows Live Writer, and found and fixed a variety of bugs that were preventing the two from working together in peace and happiness etc.

I've tested adding a post, editing a post, including categories (which was one of the sources of trouble), retrieving recent posts, retrieving one of those posts for editing, and uploading images. I now have working implementations of all of these scenarios, and WLW now has no trouble with them.

So I'm reasonably confident in saying that after some embarrassing hiccups, niftiness has finally been achieved.

BlogApi fix

I just discovered a bug in my code for the MetaWeblog API getRecentPosts command - I was passing postId (which in this case is naturally empty) to the implementation method rather than blogId. So embarrassing.  Lucky nobody was actually using it :-)

The updated code can be found here.

I discovered this one since I'm writing an implementation for my own web site which I'm currently putting through its paces.
Other than that stupid, stupid little slip it's coming on quite well.

MetaWeblog API library stuff part 2: Hints on implementing a BlogProvider (corrected typo in earlier version of title)

Technorati Tags: MetaWeblog API, WCF

Notice I said "hints", I don't want to raise anyone's expectations unduly :-)

One thing before I start: If you're working with the code from my previous post and construct a POX service using those guidelines, the url will be something like "(site name)/(application name)/blogservice.svc/metaweblog". This can probably be made friendlier on IIS7 but I haven't tried yet.

Anyway, here's  the simplest and most utterly useless implementation of IBlogProvider.
You'll notice that every method is a stub returning a NotImplementedException. That won't even allow you to register your test blog site with a blog client, although it will return an XML-RPC fault structure containing the error text, which is a test in itself.

To register your blog with a blog client application you'll need to have the GetUsersBlogs method actually return a BlogInfo struct (in the C#, not XML-RPC sense) populated with some convincing values.

To do some decent testing (and as a starting point for a real implementation) you can download this version: It doesn't actually read any real data or edit any real blog posts, but it does an adequate job of pretending. The exception is the NewMediaObject method, which still returns a NotImplementedException. Any implementation must return a url for the uploaded file, as mentioned in the code comments.
If you read that file you'll notice frequent calls to ValidateUser(), declared at the end of the class as a partial method (one of the nifty new features in .NET 3.5/VS 2008). If you include this optional implementation of the partial method, the user credentials supplied will be checked against the ASP.NET Membership Provider, and the user will additionally be checked to see whether they are in the role specified in the blogUserRoleName application setting (that is, in the  appSettings section in your config file). You can of course change the code to validate against anything you like.

FakeBlogProvider.cs hopefully contains enough comments to point you in the right direction to create a working implementation of IBlogProvider.
It goes without saying that all the code presented here and in the previous post is provided "as is" (well of course, how could it be provided "as it isn't" ?), with no assurances or guarantees as to its quality, accuracy, or fitness for any purpose whatsoever. And I can guarantee it will not improve your social life.
Anyway, if you find this useful I'd be interested to hear about it, so feel free to use the contact form and let me know.

MetaWeblog API library for .NET 3.5 (esp. WCF)

Technorati Tags: MetaWeblog API, .NET, WCF

[UPDATE 14/01/2008: A new version of the code is now available with numerous (OK, several) bug fixes, following testing in the real world]

The clock is about to tick over into 2008 here in Godzone, and all over the country happy drunks are merrily beating each other senseless. I can already hear local members of the knuckle-walking community cheerfully grunting to one another in what passes for a greeting among those of us whose ancestors spent insufficient time banging the rocks together...(I can think of no better way to start the new year than to insult 90% of the population. It'll save time later)

But I myself am sadly once more slaving over a hot keyboard. At least for a few more minutes (I have however marked the occasion by cracking open a Stella. But I digress). The reason I'm posting at this late hour is to make available the first version of a library I've written for Blog servers to work with the MetaWeblog API (as I've said before, I loathe XML-RPC, but you have to be pragmatic about these things). This means that you can enable your blog (if it doesn't have such support already) to work with tools such as Windows Live Writer. Which is nifty.

The idea is that you grab the aforementioned code from here, write a class implementing the IBlogProvider interface (I don't like using the -Provider name for something that isn't an ASP.NET Provider, but I couldn't think of anything better), and use said class to mediate between your data store (and if appropriate, file system) and the MetaWeblog-parsing-and-regurgitating code which is abstracted away into the MetaWeblogManager class. The library defines a few data structures such as BlogInfo, UserInfo, CategoryInfo and BlogEntry to enable complex data to be passed back and forth between MetaWeblogManager and its BlogProvider (the class you'll write to implement IBlogProvider) without the latter having to deal with or know about XML-RPC gunk.

Please note that this library requires .NET 3.5, as it relies heavily on LINQ to XML (and as you can see the following implementation bits use 3.5 as well).

It's designed to work with WCF 3.5 SOAP-less services, but could be made to work with something like an HttpHandler as well with a little extra code to convert between XElements and Request/Response stream content.

An example WCF contract looks like this:

using System.ServiceModel;
using System.ServiceModel.Web;
using System.Xml.Linq;

[ServiceContract]
public interface IBlogService
{

    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare,
        RequestFormat = WebMessageFormat.Xml,
        ResponseFormat = WebMessageFormat.Xml, Method = "POST")]
    XElement MetaWeblog(XElement request);
}

The implementing service being something like:

using System.Xml.Linq;
using Daly.Blogging;

public class BlogService : IBlogService
{
        MetaWeblogManager manager = new MetaWeblogManager { BlogProvider = new TestBlogProvider() };
        public XElement MetaWeblog(XElement request)
        {
            return manager.Execute(request);
        }
}

Note that TestBlogProvider is just an example - this would be whatever class you create to implement IBlogProvider.

I have to admit that for something so tiny separating the contract stuff out into a separate interface is a bit precious, so feel free not to do that. But that's just my opinion, I know some of you have Very Strong Views on that sort of thing.

The config for this service looks like this:

<system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="blogBinding" maxReceivedMessageSize="204800" ></binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="BlogService">
        <endpoint address="" behaviorConfiguration="Daly.Blogging.WebBehaviour" bindingConfiguration="blogBinding"
         binding="webHttpBinding" contract="IBlogService" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebBehaviour">
          <webHttp />
        </behavior>
        <behavior name="Daly.Blogging.WebBehaviour">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

This is actually only necessary in this case if you plan to support metaWeblog.newMediaObject and allow media files larger than about 20K (maxReceivedMessageSize has to be bumped up from its default 64K to allow for the base64-encoded-and-therefore-expanded file contents) - otherwise you can leave out the system.serviceModel config entries and include a Factory="System.ServiceModel.Activation.WebServiceHostFactory" attribute in your .svc file.

To answer a few questions you may have:

  1. What's with all this Daly.Blogging nonsense? - It's not, in fact, because I have an enormous ego (that's a coincidence). I've just used that namespace to avoid name collisions with your own code.
  2. Why use an interface instead of an abstract class for the "BlogProvider"? - Good question. I might change my mind about this later.
  3. Why are the (very few) fault code numbers defined as constants instead of an enum? - To avoid casting them back to System.Int32, and because they are never read, only written (er, that sort of made sense to me at the time).
  4. Why not implement a proper ASP.NET Provider?  - I planned to do this at one point (Sunday afternoon, to be precise), then decided that it didn't really fit the use case. The truth is that the provider will always be a custom implementation that you write yourself, there is no useful default or pre-packaged version. So there's not much point in providing declarative support. That being the case, I decided to keep it simple and avoid the Reflection overhead. For those who are interested in such things this implementation is more or less a Strategy pattern.

I may update the code over the next few days. I also intend to provide some useful information about implementing a BlogProvider, unless I forget. Or get hit by a meteorite. You know, stuff.

Anyway, Happy New Year.

Visual Studio 2008 includes a refreshed image library

Technorati Tags: Visual Studio 2008

I haven't seen this mentioned anywhere, but as the title of this post says Visual Studio 2008 includes an updated version of the image library (icons, bitmaps and so on for use in applications) that shipped with Visual Studio 2005.

More consistent and helpful categorisation has been introduced to the organisation of the library, there is an entire category of common elements to be included in new imagery, and most importantly from my point of view there is new Vista-specific imagery, something that was definitely on my wish list.

This will be good news for anyone who noticed that the library that shipped with the betas was unchanged from Visual Studio 2005 and may have been worried that that's all we'd get.

This is another touch that may seem small by itself but is one of the many elements that make Visual Studio 2008 the first version that really seems at home on Vista (apart from anything else, the VS 2005+VS 2005 SP1+Update for Vista setup reminded me uncomfortably of the bad old days of NT4 + Whatever The Hell Service Pack That Was + the NT 4 Option Pack just to run ASP...ah, those were the days. But I digress).

ZamDes inaugural meeting

As the title (see, that big header-ish thing up there...I'd point but I can't) implies I attended the first meeting of the ZamDes user group in Wellington tonight.

Kudos (even though I hate that word) to Nas and Isha for putting on a very good presentation.

I think this is going to be an excellent way of sharing information and tips and stuff (I've been awake for a whole day so I can't think of more intelligent words than "stuff". But it's a perfectly good word anyway). I'm looking forward to seeing how the web site develops.

And I enjoyed my lollipop.

Off Topic: Riverbend has posted again

This has nothing to do with anything technical or even geeky, but there is a wider world, the one that actually matters.

Those who have been following the blog of the Iraqi who writes as Riverbend will be pleased to know she has posted again, covering her family's escape to Syria.
I'm relieved to know they got out, and filled with sadness and cold rage that they and so many others had to.

Go read Riverbend's latest now, and then everything else on her blog.

Then study war no more.

Tip for NZ Daylight Saving changes

Those of us working in New Zealand will probably be aware (or should be aware) that our government in its wisdom decided on very short notice (on the principle that Anything I Don't Understand Isn't Important) to extend daylight saving from this year, basically to squeeze more money out of the tourists.

The updates for Windows are mostly available, but there is nevertheless room for uncertainty about whether any given machine has been patched.

A nice feature added to the DateTime structure in .NET 2.0 is the IsDaylightSavingTime method, which enables the following expression which can be run on any machine in the NZ timezone to test whether the daylight saving patch has been applied:

new DateTime(2007,9,30,3,0,0).IsDaylightSavingTime()

So there you go.

Belated TechEdNZ07 Wrap up

Technorati Tags: TechEdNZ07

 I originally meant to blog at least once a day during the event, but unfortunately I forgot to take the charger adapter for my Harrier (yeah, I know. I'm so embarrassed).
I didn't get back till Thursday night and I've spent a couple of days catching up on things (and sleep).

Since I obviously didn't attend every session any impressions I give of the dominant themes are naturally coloured by my own interests (although I will refrain from discussing young women with feathers on their heads, despite having found that very interesting).
    One standout though not only from my own impressions but from talking to other developers was Silverlight: actually, I'm very pleased about this because it means that I'll be able to bring it up as an option without spending so much time trying to explain what it is. Of course the really cool stuff will come about a year from now (guessing wildly) when 1.1 becomes available.
I think Silverlight will also provide a pathway for some developers leading to WPF, which hasn't received the attention it deserves outside compulsive early adopters like yours truly. Partly I think this may be because Microsoft oversold the designer/developer split, leading many developers to assume that WPF wasn't for them. I expect this to change.

Another biggy was obviously Visual Studio 2008, although I was surprised that more wasn't being made of it. 
   Of the features that will actually be available when Visual Studio 2008 is released (so excluding Silverlight 1.1 and the ASP.NET Futures stuff), the most significant in terms of new language/platform functionality (as opposed to IDE improvements) is probably LINQ...we all tend to zoom in on LINQ to SQL but I hope people don't ignore the other flavours: I recently worked on adding support for some fairly complex new business rules to a commerce site, which involved writing predicate syntax queries against generic collections - a very cool feature of .NET 2, but it would all have been much, much easier with LINQ.
   As regards LINQ to SQL, I do hope developers will see it not so much as Just Another ORM or Something The DBA Probably Won't Like and actually get a feel for the benefits of adding querying capabilities to the language itself (seeing beyond the database scenarios will help in this).
  I'm curious as to what LINQ to XML might be able to bring to the interaction with POX web services, although in those cases where XML-RPC is used, it's so bloody awful I doubt anything would help (no doubt Darryl would say I was being cynical about that :-) ). But that's not the fault of LINQ.
  The LinqDataSource for ASP.NET should complete the process of making drag-and-drop databinding for web applications backed by a database not only useful but also respectable. Being able to bind to ObjectDataSources and thence to TableAdapters in VS 2005 was a good step in this direction, but maintaining the relationship between database, adapter, datasource and control can be a source of pain and anguish (and cryptic error messages), so LinqDataSource is a very welcome addition. 

TechEd keynote

After the usual noise and fluff that preceded it Lou Carbone's keynote was actually very good...I'd expected a lot of marketingspeak so it was a welcome surprise.

Technorati tags: TechEdNZ07

TechEd 2007 (NZ)...The Foremath

Technorati Tags: TechEdNZ07

(Well,  if you can have an aftermath, why not a foremath, eh?)

Next week is TechEd week here in New Zealand (well, in Auckland, which qualifies as New Zealand if you want to stretch a point...although I've always regarded it as Greater Sydney)

There should be a lot of interesting content this year, especially with the 2008 wave within smelling distance of release and the ever-nifty Silverlight attracting a lot of attention.

I've attended every TechEd of the honest-to-goodness-actually-released .NET era, but until this year I've never been able to attend the drinks on the last day because I've always been in a mad dash to the airport at that time.
Fortunately however, this year I don't fly out until Thursday, so I'll finally be able to stay for drinks on Wednesday as God intended.

Of course, if anyone has any good ideas about drinks at any other time I'm always open to constructive and imaginative thinking on this subject.

Visual Studio 2008 Beta 2 is on MSDN

Just thought you might like to know.

Where's the Visual Studio patch for .NETCF2 SP2?

Back in March the redistributable for the .NET Compact Framework v2 SP 2 was released. As usual the team blog listed the various er, variations and so on with links to be added as the appropriate releases became available.

These have all now been filled in - with the exception of the patch for Visual Studio 2005.

As a developer this is a big deal for me - I have been delaying installing the refresh of the Windows Mobile 6 SDK (which lists .NETCF2 SP2 as a prerequisite) precisely because I don't want to find myself with a version which I have to uninstall and replace in order to be able to test and deploy correctly from Visual Studio.

With SP1 a big deal was made about having to apply the VS2005 patch and how you would have to uninstall the redistributable if you'd installed it first, and the fact that a patch is listed at all on the blog page implies that the same is true (or intended to be true) for SP2.

 

So Compact Framework Team, where is it?

Silverlight for Windows Mobile - Some items from my wish list

Silverlight for Windows Mobile looks like it's (unfortunately) a good way out, or possibly something that might never see daylight.
Still, there's been a little preview and it looks pretty nifty.

I really, really hope Microsoft deliver it in a form that can run standalone applications (i.e. without having to be deployed from a web server), and with the Silverlight runtime using the full .NET CF 3.5 (I assume) runtime.
I also hope of course that they deliver it within my professional lifetime :)

The UI options for Compact Framework developers are pretty dire: without writing interop code or giving up and just going native, you're limited to something that largely has the visual polish of VB5. It's not pretty.

Silverlight on the other hand gives us the opportunity to create flexible, imaginative and frankly gorgeous UI. It's a shame that it doesn't include the advanced Panel features of WPF (because that would be a handy answer to the horror of resolution and orientation awareness), but some compromises are inevitable. It would still be a huge step forward, and I'd love to see it available as an option for the generality of device applications.

Last but not least, Silverlight+.NET CF+thousands of developers using an application-friendly(-ish) platform enables a good response to the iPhone (if nothing else the iPhone does raise expectations for mobile UI, and we won't be able to get away with more of the same old same old).

 

Productivity

Thought for the day: If I thought lines of code were truly a useful measure of productivity, I'd stop using the ternary operator.

But I won't.

Community Server 2.1 and newMediaObject - (Windows Mobile 5 app CAB link now included)

(Updated 11:07 pm with info about service packs)

In a recent post I mentioned the MetaWeblogAPI's newMediaObject method and the fact that it's finally beginning to be supported by popular blog hosting tools.

Well, a few days ago I went ahead and released version 2.1 of Diarist, with support for uploading image files (jpeg, gif or png...you didn't honestly want tiff did you? from a mobile device?) to blog hosting sites that support newMediaObject.

(I didn't post anything about it at the time because I'm sure that Dotnetjunkies readers are sick of me posting about Diarist updates. I'd write some "How-to"'s but I'm still exhausted from writing code...).

Anyway, this is just a piece of information for people who are hosting their own Community Server 2.1 sites: apparently newMediaObject support was released late last year as an add-on, which you can get here if you don't already have it and haven't installed/don't want to install Service Pack 2 or later.
It was also included in in Service Pack 2 (I think they're up to Service Pack 3 now)

I hope you find that helpful.

Now I'll return to carefully avoiding any British blogs that might contain references to the final episode of Life On Mars (which I won't see for about another year) (...unless some wise company offers me a job over that side of the world, in which case I'll have to get it on DVD. But I digress. Even more than usual).

 

Update: Thursday, 26/04/2007

Users of Windows Mobile 5 devices or later may be wondering why I'm not using either the image picker or the camera capture dialog.

The first reason (which applies to both) is that the current program is designed to run on both Windows Mobile 5 (or 6) and Windows Mobile 2003 (which doesn't include either of those options).
Regarding the camera capture dialog specifically, the other reason is that I completely forget about it until Jason Barile reminded me.

I've decided however that these omissions create an unnecessarily crappy experience for users of Windows Mobile 5 and later, so I'm planning to make a separate version available for those lucky bast people.

Unfortunately I don't have any way to test the camer