Click here to Skip to main content
16,016,425 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey guys!
I developed a ASP.NET Web Api (2.2) with odata support. The API works fine, I use fiddler to get, post stuff and the api handles everything fine.

Now I'm trying to write a C# library that consumes the API. Now I used to have a API without odata support and the following code works just fine :
C#
var url = "Support/Tickets";
HttpResponseMessage response = client.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
{
    var list = response.Content.ReadAsAsync<List<Tickets>>).Result;
}

(client here is a System.Net.Http.HttpClient object)

However, since I implemented the odata solution, the JSON returned from the API is changed :
C#
{
  "odata.metadata":"http://url.to/Support/$metadata#Tickets","value":[
    {

    }
  ]
}


Now the bold line is new and causes the line
var list = response.Content.ReadAsAsync<List<Tickets>>).Result;
to fail. The fact that the line fails I understand, but I can't figure out what way to handle the new JSON response correctly. Do I need to use some kind of odata deserializer or something?

Thanks!
Eduard
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900