C# 如何从WCF返回Json序列化数据?
我环顾四周,发现可以从WCF web服务返回序列化为Json的对象。有人知道我怎么做吗C# 如何从WCF返回Json序列化数据?,c#,json,wcf,serialization,C#,Json,Wcf,Serialization,我环顾四周,发现可以从WCF web服务返回序列化为Json的对象。有人知道我怎么做吗 谢谢您必须像这样为服务添加属性 [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json)] ObjectName YourMethodName(); 是的,您可以在web.config中将AutomaticFormatSelectEnabled设置为webHttpEndpoint的true standard
谢谢您必须像这样为服务添加属性
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
ObjectName YourMethodName();
是的,您可以在web.config中将AutomaticFormatSelectEnabled设置为webHttpEndpoint的true standardEndpoint,如
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
确保您的请求客户端正在发送“Accept:application/json”标题?您可以看到下面的链接:[return-clean-json-from-a-wcf-service][1][1]:您可以为此或链接提供教程吗?@Funky这将返回序列化为json的对象。你能详细说明一下吗?
using (HttpClient client = new HttpClient("endpoint"))
{
HttpRequestMessage request = new HttpRequestMessage("GET", "SomeMethod");
request.Headers.Accept.AddString("application/json");
...
}