Failed to return json data, WCF Resful Service.NET 4.0

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 is a Entity Class defined in edmx file
                    Deals deal = DealsServices.GetById(id);
                    return deal;

            }

where am i out

+2
source share
2 answers

Trace Viewer, . . , , , .

' "xxx.DataEntity.AppView" JSON, IsReference "True". JSON , . , IsReference . '

.

+4

, . , :

public class Obj {
   int param1 { get; set; }
   int param2 { get; set; }
};

param1 param2 null minValue ( DateTime), . , .

+1

Source: https://habr.com/ru/post/1777836/


All Articles