I have a WCF Ajax enabled web service that I call via jquery. It returns fine when I test it by just returning a string. As soon as I add some more functionality, the javascript error callback runs with no useful data. Just says ‘error’, readystate=0, status=0.
I can step through the service code and it returns an array of objects succesfully. The client doesn’t however.
Here’s the code.
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class WebAPI
{
[OperationContract]
[WebGet(ResponseFormat=WebMessageFormat.Json)]
public Person[] GetPeople(Guid groupId)
{
using (SchedulerContext context = new SchedulerContext())
{
return context.People.Where(p=>p.Group_ID==groupId).ToArray();
}
}
}
And on the client:
<script type="text/javascript">
$(document).ready(function () {
$.ajax(
{
type: "GET",
dataType: "json",
contentType: "json",
data: { groupId: 'ae09a080-5d7c-4e92-9a87-591574b7c4b8' },
url: "WebAPI.svc/GetPeople",
error: function (error) {
alert("error");
},
success: function (msg) {
alert(msg.d);
}
}
);
});
</script>
UPDATE:
Inspecting it with fiddler, the http result is 504 and in the ‘raw’ response tab has the following:
HTTP/1.1 504 Fiddler - Receive Failure
Content-Type: text/html; charset=UTF-8
Connection: close
Timestamp: 13:52:46.107
[Fiddler] ReadResponse() failed: The server did not return a response for this request.
UPDATE – 2012/05/04: (btw, happy star wars day everyone!)
I figured out that the problem was in the JSON serialising. It gives a Circular Reference Exception on my entity model. Still working on a solution.
Can you modify your service method definition to below:
Now perform a GET request from Fiddler with the request as below:
Now try to perform the same from your jquery call and see how the request looks.