Strange response from WCF service, how to return json easily
- by Exitos
I want to get a service to respond with just JSON. I have written the following code:
namespace BM.Security
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AssocFileService
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public List<Person> GetPeople(int message)
{
List<Person> myList = new List<Person>();
Person p = new Person()
{
Age = 28,
Name="Name1"
};
Person p2 = new Person()
{
Age = 26,
Name = "Name2"
};
myList.Add(p);
myList.Add(p2);
return myList;
}
}
[DataContract]
public class Person
{
[DataMember]
public string Name { get; set; }
[DataMember]
public int Age { get; set; }
}
}
But im getting the following JSON back which is really wierd...
{ "d" : [ { "Age" : 28,
"Name" : "Name1",
"__type" : "Person:#Bm.Security"
},
{ "Age" : 26,
"Name" : "Name2",
"__type" : "Person:#BM.Security"
}
] }
I'm totally stumped by the "d" no idea where that has come from. And also by the __type variable, no thanks don't really want that in my Json :-( How do I set the root node in my data to replace that d? Where did the d come from? So many questions...
Hope someone can help....