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.

Cool! I just gave it a short look... A few more nice ideas! Since I have followed the last .net thread, I am working on a similar implementation too! So I am counting 3 yet...
I have just started an Open Source Project and commited the code from "shibubh" with a small change in the router it self today... What do you think about merging our ideas together?

- Use JSON.NET for de- and -serialization see: http://www.codeplex.com/Json
Thinking about restrict to the use of Static classes or even support them. (This is importent cause of performance issues in big applications)

So As i have Seen so far your version solves the second point nicely... But what do you think about the first one?

Modofications

Modofications

That was great!

But the issue is if you have tons of pages in one assembly that need lots of Ajax function for different purposes, it renders all methods to every page while it might not be needed, so I made some modification (in sample application not Library), hope that helps:

Instead of including ApiHandler.ashx as a script block, I used it as a helper class like this:

Inside of Ext.onReady method in default.aspx page, every thing is ready to go to use functions that are defined in pages. So every page has access to it's own functions only, that help organizing methods.

Note: When registering an action, it gets name of page's type, that returns 'default_aspx' instead of Default, so I had to call:
default_aspx.Echo(.....);

Alek.

PS: adding provider can be moved to Register function in helper class like this:

1) Native date support. Since both Ext.encode() and the native browser JSON encoders send off dates as string, the router will automatically find date arguments in the server method and attempt to convert the parameter to a date.

Bug in the router

Bug in the router

Hi, Evan. Just a quick thing, there's a bug in your implementation of Direct router. A null reference exception is thrown if you call a direct method with no parameters.

The exception is thrown from DirectProvider.cs line 187.

PHP Code:

if (request.Data == null && method.Parameters > 0){ throw new DirectException("Parameters length does not match");}else if(request.Data.Length > 1 && method.IsForm) // <--- EXCEPTION IS THROWN HERE: request.Data is null{ throw new DirectException("Form methods can only have a single parameter.");}else if (request.Data.Length != method.Parameters){ throw new DirectException("Parameters length does not match");}

To fix it I've replaced this piece of code with this:

PHP Code:

if (request.Data == null){ if (method.Parameters > 0) { throw new DirectException("Parameters length does not match"); }}else{ if (request.Data.Length > 1 && method.IsForm) { throw new DirectException("Form methods can only have a single parameter."); } else if (request.Data.Length != method.Parameters) { throw new DirectException("Parameters length does not match"); }}