首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ResponseFormat返回0字节

ResponseFormat返回0字节
EN

Stack Overflow用户
提问于 2014-09-22 01:19:53
回答 1查看 106关注 0票数 0

我想做一个JSON返回格式的REST web服务。实际上,它适用于简单的字符串返回类型,但当我使用自定义类型作为返回值时,我会收到0字节。

如果我将ResponseFormat更改为XML,它就能正常工作

谢谢你的帮助!

编辑-添加样本

接口:

代码语言:javascript
复制
[WebGet(UriTemplate="WebGetTry/{param1}/{param2}", ResponseFormat=WebMessageFormat.Json)]
WebGetType WebGetTry(string param1, string param2);

实施:

代码语言:javascript
复制
public WebGetType WebGetTry(string param1, string param2) {
  return new WebGetType();
}

之后,我的测试就是简单地从IE调用地址。返回页面无法显示错误

EN

回答 1

Stack Overflow用户

发布于 2014-09-22 11:25:49

您需要指定JSON端点的实现。请检查您的web.config并添加以下内容:

代码语言:javascript
复制
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
        <webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json"/>
  </webHttpEndpoint>
</standardEndpoints>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25961835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档