c# - 如何将 JSON 设置为 WCF 服务的默认值

标签 c# json wcf

如何将 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/

相关文章:

c# - 通过 C# 中的递归将 Flat List<T> 转换为结构化 List<T>?

c# - 在 TFS 中取消 "get latest version"是否有效?

jquery - 使用 jQuery/Ajax 将 JSON 文件数据存储在 localStorage 中

.net - 声明 ClientBase 期间设备崩溃

.net - .NET Remoting 真的已被弃用吗?

c# - 如何为 Json.net 生成 json 对象的所有可能的 LINQ 字符串?

c# - NDatabase 在 Order By 上崩溃

javascript - Json返回每个函数

json - 如何在ajax调用中压缩web服务响应json

WCF服务设计问题