I am calling my web api from my C# desktop client.
This is my code on the client:
public IEnumerable<Model.Print> Get()
{
var print = new List<Model.Print>();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(Shared.URL);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(Shared.HeaderType));
var response = client.GetAsync(route + "?" + GeneralTags.CUSTOMER_REF + "=" + new Guid().ToString()).Result;
if (response.IsSuccessStatusCode)
{
string strJson = response.Content.ReadAsStringAsync().Result;
var jObj2 = (IEnumerable<Model.Print>)JsonConvert.DeserializeObject(strJson);
}
else
{
evError(new Exception(String.Format("{0}: {1}", (int)response.StatusCode, response.ReasonPhrase)), ErrorTags.PRINT_GET);
}
}
return print;
}
But I get an error on this line:
var jObj2 = (IEnumerable<Model.Print>)JsonConvert.DeserializeObject(strJson);
The error is:
'Newtonsoft.Json.Linq.JArray' to type 'System.Collections.Generic.IEnumerable`1[InformedWorkerServer.Model.Print]'.
The strJson contains a value:
[
{"PrintId":1,"PrintRef":"00000000-0000-0000-0000-000000000000","Header":"header","TC":"tc","CompanyRef":"00000000-0000-0000-0000-000000000000"},
{"PrintId":2,"PrintRef":"39a10cee-7cb3-4ed3-aec2-293761eed96d","Header":"header","TC":"tc","CompanyRef":"00000000-0000-0000-0000-000000000000"}]
What am i missing?