The main reason I am posting this really simple post only because, even though it is simple, it wasted a lot of time for me. There are several ways to enable JSON request and response for WCF web service. But the easiest I think is this one
1. Just select AJAX Enabled Web Service from the add new item window if you are using Visual Studio ( I used VS2010). By default this will talk to the clients with JSON. There you go.
2. But, If you really want to know whats the difference between AJAX Enabled Web Service and WCF Web Service, open the new added AJAX Enabled Web Service. Just over the class declaration you will notice a line that says –
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
The second line is the main reason. It enabled the service to allow JSON type messaging from a client.
Now, I know this is not the only solution, you can also enable JSON response/request in a WCF Service, but I have not really tested that case, will post as soon I am done…
If this is found helpful, don’t forget to leave a comment, thanks.