I'm a bit late to this question, but hopefully this helps you or anyone else stumbling onto this thread later.
You definitely can use ASMX services to communicate in JSON.
Your service code looks okay. Since you aren't showing how you're calling it, I'll bet that's where your problem lies. One requirement for getting JSON out of ASMX "ScriptServices" is that you must call them with the correct content-type header and you must use a POST request. Scott Guthrie has a good post about the reasoning behind those requirements.
So, if you just request DemoService.asmx/GetCustomer
in a browser, you're going to get XML. However, if you make a POST request with an application/json
content-type, you'll get the same result serialized as JSON.
If you're using jQuery, here's an example of how you would request your DemoService on the client-side:
$.ajax({
type: "POST",
contentType: "application/json",
url: "DemoService.asmx/GetCustomer",
data: "{}",
dataType: "json",
success: function(response) {
// Prints your "Microsoft" response to the browser console.
console.log(response.d);
}
});
More here: http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/