There are many reasons create a RESTful WCF server (it is easy) and even better if you can avoid ASP and it's security box (if all you are doing is simple requests to return information). See: http://msdn.microsoft.com/en-us/library/ms750530.aspx on how to do this.
What I found is that handling AJAX (JQUERY) GET requests is easy. But dealing with JSON in a POST is tricky.
Here is an example of a simple GET request contract:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
String Version();
And the implementaion is here (which returns a JSON)
public partial class CatalogService : ICatalogService
{
public String Version()
{
mon.IsActive = true;
this.BypassCrossDomain();
ViewModel.myself.TransactionCount++;
return ViewModel.myself.VersionString;
}
}
Ah, but what if you want to POST some JSON. You will find lots of articles on stack overflow that tell you all you have to do is this:
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
BuildResponse BuildToby(BuildRequest request);
which will receive a JSON message, de-serialize into a Plain .NET object (PONO) and let you work with it. And indeed, this worked fine when I constructed the request in Fiddler.
POST /BuildToby HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:4326
Content-Length: 1999
However, when you use the following AJAX in JQUERY 1.8, you will find a SURPRISE:
It by specifying content-type of "application/json" you will find that there is a "preflight" check that is fired off by the browser to see if you are allowed to POST something other than a www-url-enclod