Calling WCF service with jquery and parameters synchronously
I am calling a .NET WCF service from Ajax like this:
result = $.ajax({
type: "POST",
// async: false,
contentType: "application/json; charset=utf-8",
url: BaseUrl + "Services/YucataService.svc/SetGameStatusSecure",
data: "{'gameID':'" + gameID + "','pid':'" + pid + "','status':'" + newStatus + "','origStatus':'" + oldStatus + "'}",
dataType: "json",
timeout: 20000
});
The server part looks like this:
[OperationContract]
public void SetGameStatusSecure(int gameID, int pid, string status, string origStatus)
{
... magic stuff happens
}
It works well.
Now, I would like to call the service synchronously. The only change I do is to add "async: false". The call return with status 500 (=internal server error).
Do I have to configure the WCF service differently to allow sync calls?
Before I switched to WCF I used an .asmx service to开发者_运维问答 call synchronously and I didn't have any issues.
Any ideas?
I think by default WCF accepts Synchronous calls. If you want to make it asynchronous, you need make sure you check “Generate asynchronous operations” under Advanced tab. (at the time of adding service reference). Be default, this check box is always unchecked.
精彩评论