1

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?

Venkateswararao
  • 343
  • 1
  • 5
  • 19
  • Check this article http://prideparrot.com/blog/archive/2011/9/returning_json_from_wcfwebapi – VJAI Sep 15 '11 at 14:03

1 Answers1

5

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

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243