2014-09-21 57 views
0

我想使用JSON返回格式创建REST Web服务。实际上它是为一个简单的字符串返回类型工作,但是当我有一个自定义类型作为返回值时,我收到0字节。ResponseFormat返回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浏览的地址。返回页面无法显示错误

+1

请向我们展示一些用于返回响应的代码。 – reptildarat 2014-09-21 17:27:38

+0

谢谢,编辑了原帖。 – pillesoft 2014-09-21 18:05:16

回答

0

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

<system.serviceModel> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    <standardEndpoints> 
     <webHttpEndpoint> 
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json"/> 
    </webHttpEndpoint> 
</standardEndpoints> 
+0

谢谢,但这不是一个真正的解决方案,我仍然没有json结果 我认为最好的是,如果你下载,WCF REST项目模板[链接](http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd)或者您从Web API开始 – pillesoft 2014-09-23 11:34:24