I’m currently new into client-side programming, especially using the Jquery Ajax method to call server-side methods.
Until now I’ve used a System.Web.Services.WebService to host multiple methods to return a String or a bool. This approach has the advantage, that I can “group” methods with a similar purpose, like “methods for a comment-system”. A disadvantage, as I’ve read many times, is that *.asmx services are outdated and the Json support isn’t that well.
I’ve always read that a good way to provide methods that return JSON objects is the use of generic handlers (*.ashx). Generic handlers that I’ve written in the past provided only one single “action” per handler.
Is using generic handlers for a JSON datasource the way to go? I clearly see the disadvantage of not being able to “group” methods, because each method would be in a seperate .ashx.cs file. (I know that I could pass a second argument that determines which “action” should be called, but somehow doesn’t feel right).
Using a WCF service is not a worthwhile option at the moment, because the methods that I use need access to the session and adjusting a service to fit the same purpose is just an overkill for now.
I guess the real question is: What is a modern way to return JSON objects / List of JSON objects while maintaining readability / structure of the service-side methods?
Edit: I’m using Webforms 4.0
I have moved onto MVC, which makes this sort of thing a lot easier. But when I did this in WebForms, I would use one or more handlers (ASHX) that took in an action parameter. The action parameter would then be evaluated against to call the appropriate target method which would handle the response.
If you go this route, you’re saving yourself the headache of all those files. And what you lose in having to specify an action parameter on your ajax calls, you gain in not having to specify different file names.