I am calling on a WCF Data Services v3 Odata service. I am having trouble getting my collection filled in the below example. I am able to get a json string of the 3 people, but if I try and get a custom collection filled, the collection has a count = 0.
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.BaseAddress = new Uri("http://localhost:7500/Wcf1.svc/People");
HttpResponseMessage resp = client.GetAsync("").Result;
string jsonString = resp.Content.ReadAsStringAsync().Result;
List<Person> personCollection = resp.Content.ReadAsAsync<List<Person>>().Result;
jsonString has 3 people in it.
personCollection has a count = 0.
the jsonString looks like this:
{"d":[
{"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(1)",
"uri":"http://localhost:7500/Wcf1.svc/People(1)",
"type":"WcfService1.Person"},
"ID":1,"Fname":"Fred","Lname":"Peters","Address1":"123 Main"},
{"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(2)",
"uri":"http://localhost:7500/Wcf1.svc/People(2)",
"type":"WcfService1.Person"},
"ID":2,"Fname":"John","Lname":"Smith","Address1":"123 Oak"},
{"__metadata":{"id":"http://localhost:7500/Wcf1.svc/People(3)",
"uri":"http://localhost:7500/Wcf1.svc/People(3)",
"type":"WcfService1.Person"},
"ID":3,"Fname":"Tom","Lname":"Anders","Address1":"123 Hill St."}]}
I must be doing something wrong, please point out my error if you can.
Thanks. Terrence
>().Result;
>().Result; If you have time, could you re-read my original post. Shouldn't this line work? Have you ever gotten a collection populated with the syntax I am using? Thank you for keep up with this conversation.