如何将 JSON 设置为 WCF 服务的默认值?
我知道要以 JSON 而不是 XML 的形式返回数据,我可以使用:
[WebInvoke(UriTemplate = "Customers/{id}", Method = "PUT",
RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
有没有一种方法可以让我将 JSON 作为默认值,这样我就不需要为每个方法指定格式?
最佳答案
希望这会有所帮助:
<behaviors>
<endpointBehaviors>
<behavior name="jsonEndpoint">
do not specify enableWebScript or UriTemplate will not work
<webHttp defaultOutgoingResponseFormat="Json"/>
</behavior>
</endpointBehaviors>
</behaviors>
关于c# - 如何将 JSON 设置为 WCF 服务的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21698324/