返回JSON的WCF [英] Return JSON from WCF

查看:329
本文介绍了返回JSON的WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WCF服务是.NET Framework 3.5的,这WCF服务将使用PHP,所以我用basicHttpBinding的(请建议是否有其他更好的)。

my WCF service is in .net framework 3.5,this WCF service will be used by PHP, so i have used basicHttpBinding (please suggest if any other better one).

我用下面code / attribut在函数返回的JSON。

i am using below code/attribut on function to return JSON.

[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]

但它不是返回JSON(它返回的对象)。 请帮我。

but its not returning JSON (its returning object). Please help me.

注:我发现了一个解决方案,但它用于.NET Framework 4.0。但我需要3.5解决方案。 <一href="http://stackoverflow.com/questions/3781512/wcf-4-0-webmessageformat-json-not-working-with-wcf-rest-template">WCF 4.0:WebMessageFormat.Json不工作与WCF REST模板 谢谢

NOTE: i found a solution but its for .NET Framework 4.0. but i need solution for 3.5. WCF 4.0 : WebMessageFormat.Json not working with WCF REST Template Thanks

推荐答案

你有没有添加AspNetCompatability属性为您服务实现类?

Have you added the AspNetCompatability attribute to your service implementation class?

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ServiceImpl{
}

另外,更改您可能需要更改绑定到的WebHttpBinding basicHttpBinding的是SOAP而不是JSON的

Also, change you might need to change your binding to webHttpBinding as basicHttpBinding is for SOAP rather than Json

这篇关于返回JSON的WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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