Venkateswararao
Venkateswararao

Reputation: 353

WCF Web API Json Format

I am new to WCFweb api WEb service in MVC I did a sample service using ADO.net Entity frame work it return result in XMl format I want to Json format I wrote the code like that.

   [WebGet(UriTemplate = "ListAccount", ResponseFormat = WebMessageFormat.Json)]

    public IEnumerable<account> Get()
    {




        IEnumerable<account> objAcct = from cat in objEntity.accounts select cat;
          List<account> Result;
        Result = new List<account>();
        foreach (account Account in objAcct)
        {

            account objAcc = new account();
            objAcc.AccountNumber = Account.AccountNumber;
            objAcc.AccountType = Account.AccountType;
            objAcc.BusinessName = Account.BusinessName;
            objAcc.AccountId = Account.AccountId;
            objAcc.PrimaryContactFirstName = Account.PrimaryContactFirstName;
            objAcc.PrimaryContactLastName = Account.PrimaryContactLastName;
            objAcc.PrimaryContactEmail = Account.PrimaryContactEmail;
            objAcc.PrimaryContactPhone = Account.PrimaryContactPhone;
            objAcc.AccountGuid = Account.AccountGuid;
            Result.Add(objAcc);
        }

        return  Result.AsQueryable();

    }

Please help me how can i get Json format result?

Upvotes: 1

Views: 1171

Answers (1)

Darrel Miller
Darrel Miller

Reputation: 142094

Try sending a Accept header with the value application/json.

Upvotes: 5

Related Questions