How do I return clean JSON from a WCF Service?

前端 未结 6 1132
借酒劲吻你
借酒劲吻你 2020-11-22 07:19

I am trying to return some JSON from a WCF service. This service simply returns some content from my database. I can get the data. However, I am concerned about the format

6条回答
  •  星月不相逢
    2020-11-22 08:05

    I faced the same problem, and resolved it by changing the BodyStyle attribut value to "WebMessageBodyStyle.Bare" :

    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetProjectWithGeocodings/{projectId}")]
    GeoCod_Project GetProjectWithGeocodings(string projectId);
    

    The returned object will no longer be wrapped.

提交回复
热议问题