我想做一个JSON返回格式的REST web服务。实际上,它适用于简单的字符串返回类型,但当我使用自定义类型作为返回值时,我会收到0字节。
如果我将ResponseFormat更改为XML,它就能正常工作
谢谢你的帮助!
编辑-添加样本
接口:
[WebGet(UriTemplate="WebGetTry/{param1}/{param2}", ResponseFormat=WebMessageFormat.Json)]
WebGetType WebGetTry(string param1, string param2);实施:
public WebGetType WebGetTry(string param1, string param2) {
return new WebGetType();
}之后,我的测试就是简单地从IE调用地址。返回页面无法显示错误
发布于 2014-09-22 11:25:49
您需要指定JSON端点的实现。请检查您的web.config并添加以下内容:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json"/>
</webHttpEndpoint>
</standardEndpoints>https://stackoverflow.com/questions/25961835
复制相似问题