I recently created a WCF Resful service with Entity Framework 4.0. It works fine with XML, but 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?
early
Edit:
The code is quite normal, in fact I tried two ways to do this, 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 the ResponseFormat path:
[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 deal = DealsServices.GetById(id);
return deal;
}
where am i out
source
share