How to return Json from WCF Service?

Posted by Zinoo on Stack Overflow See other posts from Stack Overflow or by Zinoo
Published on 2009-12-02T03:18:02Z Indexed on 2010/06/08 23:12 UTC
Read the original article Hit count: 214

Filed under:
|

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;
    }
}

© Stack Overflow or respective owner

Related posts about wcf

Related posts about JSON