WCF, Prototype, And Awesome-sauce

One of the most awesome features of WCF in .NET 3.5 is support for REST-style AJAX requests to the services.


Rick Strahl has an excellent post on how to get it up and running with jQuery.


Just some notes on working with it myself which I hope can help clarify some some issues:



  • When using POST and the postBody option with Ajax.Request, the format must be {“argument-name”:”value”}.  I struggled with this for a while using single quotes and no quotes.  For example: {arg:’hello’}, {‘arg’:’hello’}, {arg:”hello”} will all result in 400 “Bad Request” errors.
  • The contentType parameter must be set to “application/json“.
  • Be sure to decorate the service contract using the WebInvokeAttribute with ResponseFormat and RequestFormat set to WebMessageFormat.Json.

You can download a sample project from here: WcfAjaxSample.zip (3.83 KB)

You may also like...