This project is read-only.

Help with syntax on getting a collection

Topics: Web Api
Jan 11, 2012 at 4:00 AM
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 eee = resp.Content.ReadAsStringAsync().Result;

 List<person> perlist = resp.Content.ReadAsAsync<list<person>>().Result;

I am trying to get a List<person> from my service.

Can someone help with the syntax?

Thank you

Jan 11, 2012 at 4:46 AM

Does the above code not work? What issue are you running into?

Daniel Roth

Jan 11, 2012 at 1:40 PM

Daniel, the perList is empty.

If I uncomment the line above it and populate the eee string, it is populated with a json collection of 4 people.

Populating a List<Person> perList does ot work, it has a count of 0.

Thank you for your help.