WCF 4.0:WebMessageFormat.Json 不适用于 WCF REST 模板 [英] WCF 4.0 : WebMessageFormat.Json not working with WCF REST Template

查看:20
本文介绍了WCF 4.0:WebMessageFormat.Json 不适用于 WCF REST 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

this 位置.

默认的响应格式是 XML,效果很好.但是,当我尝试获得 JSON 响应时,我仍然获得 XML.

The default response format is XML, which works great. However, when I try to get a JSON response, I still get XML.

这是我修改后的代码-

[WebGet(UriTemplate = "",ResponseFormat = WebMessageFormat.Json)]
    public List<SampleItem> GetCollection()
    {
        // TODO: Replace the current implementation to return a collection of SampleItem instances
        return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
    }

注意 ResponseFormat=WebMessageFormat.Json.这是我对该模板所做的唯一更改.

Note the ResponseFormat=WebMessageFormat.Json. That is the only change I did to that template.

我错过了什么?

谢谢!

推荐答案

想通了.标准端点的 automaticFormatSelectionEnabled 属性应设置为 false,defaultOutgoingReponseFormat 应设置为 Json.

Figured out. automaticFormatSelectionEnabled property for standardendpoint should be set to false and defaultOutgoingReponseFormat should be set to Json.

<standardEndpoint name="" helpEnabled="true" 
    automaticFormatSelectionEnabled="false" 
    defaultOutgoingResponseFormat ="Json" />

这篇关于WCF 4.0:WebMessageFormat.Json 不适用于 WCF REST 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆