4

I am implementing some AJAX which requires JSON to be returned from the server (in .NET4) but I'm a little confused on the pro's & con's of using either a custom HTTPHandler or a WCF service.

Can anyone shed some light on which would be best for a medium/large scale application which is based almost entirely around AJAX?

UPDATE

In my current use case I would need to supply a custom object to a JQuery plugin, so I would be faced with a choice between replicating these objects in .NET and then using WCF to serialize them which seems a bit of an extra unneeded step in this case. So I will go with the "string builder"/HTTPHandler model for JQuery interaction but will bear in mind the WCF method if I need to represent .NET objects on the client.

Thank you for the response.

1
  • I've seen some people actually use ASP.NET MVC and return JSON results as a JSON service. Commented Mar 5, 2011 at 18:29

1 Answer 1

1

Can you define structure of JSON messages exchanged or do you expect some arbitrary structure?

If you can define structure of JSON messages you can use WCF and its build in serialization / deserialization of JSON messages to .NET types. Requests will be directly routed to operations and you will code it as any other .NET method without bothering with JSON or serialization =>

  1. Get parameters from operation represented as .NET types / classes
  2. Process them
  3. Return .NET object as result

WCF will handle everything related to routing request to operation, deserializing parameters and serializing response.

If you can't define structure of JSON messages you can't simply deserialize them to .NET type. In such case you can go with HttpHandler and parse JSON somehow.

The difference is that WCF will do a lot of work for you but you have to do it its way. In HttpHandler you will have direct full control over request and response but you will handle all complexity by yourselves.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.