Here's my implementation of a .NET router. After seeing some of the others I've modified my original implementation a bit.

Attached is both the source for the router and a small sample project to demonstrate the functionality.


1. Setting up the Api Handler
The API describes which methods are made available to the client. In the .NET version, this is implemented as an ASHX handler. The handler instances a provider object and passes in
a) The name of the provider
b) The url of the handler for this provider
c) An assembly containing the methods for this provider

Upon calling the configure method, reflection is used to find all classes with a DirectActionAttribute. From here, any methods marked with either a DirectMethodAttribute or a DirectFormMethodAttribute will be included in the generated API. A simple caching class has been provided. It is recommended you use this to save generating the API on each call to the handler.

2. The rest

Simply setup your handler ASHX, in this case I've called it DirectHandler.ashx. From here, all we need to do is pass the appropriate provider and the HttpRequest to our processor and it will return a result.

NB: Any form methods will only be passed a single parameter, which is the HttpRequest object. Any other parameters are ignored.

Comments/questions/improvements welcome.