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)
开发者_StackOverflow中文版 {
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?
Try sending a Accept header with the value application/json.
精彩评论