Return JSON from WCF

拜拜、爱过 提交于 2019-12-08 08:36:40

问题


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).

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

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

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

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


回答1:


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

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

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



来源:https://stackoverflow.com/questions/6031364/return-json-from-wcf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!