Posts Tagged ‘metaweblog’
Sorry I have been away so long. Work has been very busy and I have been doing a lot of planning for new projects, reading, rebuilding the notebook and trying to endure winter. Needless to say I have been away for a while.
So … I have started to look in building MetaWeblog support into an MVC project and have found a dearth of examples. So after doing some reading, testing, reflectoring, etc. I have decided to role my own. “Why not?” I figure.
The first thing I tried was to create a basic MetaWeblog action model and custom model binder. The model binder (which was easy to make) worked, but it didn’t solve the big problem – I want to create individual methods for each MetaWeblog RPC, and that wouldn’t cut it. I considered making a filter, but that wouldn’t work either. So the the next thing was to try to hack the controller, and that seems to work nicely.
One of the things the MVC team has done a nice job is keeping the architecture of the MVC platform simple and open. I started using reflector to find an easy access point to inject a change to action method called and sure enough I found it the ‘HandleUnknownAction’ of the Controller class. I’ll show an example and then explain:
- So for a simple test I just wanted to redirect the action of the ‘actionName’ parameter existed. And unless you change the route defaults it’s ‘index’ – so we are good here. (The base method of HandleUnkownAction is simple – it just throws an Http error. )
- Next I injected an new route value keyed as ‘UnknownValue’ and this matches a parameter on the ‘UnknownAction’ method I am going to call. (Yes! It does bind!’)
- Last we call the ‘InvokeAction’ method on the ActionInvoker property of the controller. Important: you must return if the of the InvokeAction method succeeds. And the rest just works as if your calling a normal action method.
- The results are simple. Here is an example:
UnknownAction: Index : 1/14/2010 12:54:53 AM
So I am thinking that this would be a good basis for creating a MetaWeblog API handler using basic MVC conventions. I’ll provide more information as I get further along.