How to return Json from WCF Service?
- by Zinoo
Hi,
I have the piece of code below of a template Ajax enabled WCF service. What can i do to make it return JSon instead of XML?
thanks.
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
[ServiceContract(Namespace = "WCFServiceEight")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CostService
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
[WebGet]
public double CostOfSandwiches(int quantity)
{
return 1.25 * quantity;
}
}