I recently set up a WCF Resful Service with Entity Framework 4.0 It works with XML perfectly, however when I try to return it in json format I got
HTTP/1.1 504 Fiddler - Receive Failure
Content-Type: text/html
Connection: close
Timestamp: 01:11:06.453
ReadResponse() failed: The server did not return a response for this request.
Any Ideas??
thanks in advance
Edit: The Code is quite normal, actually i tried two way of doing it, but no luck.
Hard code ResponseFormat Way:
[OperationContract]
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Deal/{id}")]
Deals XMLDealDetail(string id);
Dynamically Set ResponseFormat Way:
[OperationContract]
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Deal/{id}/{format}")]
Deals XMLDealDetail(string id, string format);
public Deals XMLDealDetail(string id, string format)
{
OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
if (format.ToLower() == "json")
{
context.Format = WebMessageFormat.Json;
context.ContentType = "application/json";
}
else
{
context.Format = WebMessageFormat.Xml;
}
//Deals is a Entity Class defined in edmx file
Deals deal = DealsServices.GetById(id);
return deal;
}
where am i missing??