问题
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