XML to Object with HTTPClient

RosstheBoss

New Member
I'd like read the XML file and put all value in an object (if possible). I tried the piece of code below but that's not work (but the SuccessStatusCode is ok), I get the value below. Thanks,
4MK4L.png
I have this XML :\[code\]<MyFields xmlns="http://.....1" xmlns:nomc="http://......2"> <MyField Attr1="Attr1Value" Attr2="Attr2Value"/></MyFields>\[/code\]C# Code\[code\]public class MyField{ public string Attr1 { get; set; } public string Attr2 { get; set; }}_clientHttp = new HttpClient();_clientHttp.BaseAddress = new Uri("http://myServer");_clientHttp.DefaultRequestHeaders.Add("SomeHeader", "ValueHeader");_clientHttp.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));_clientHttp.GetAsync(uri).ContinueWith( (requestTask) => { HttpResponseMessage response = requestTask.Result; response.EnsureSuccessStatusCode(); var res = response.Content.ReadAsAsync<MyField>(); Console.WriteLine(res.Result); });\[/code\]
 
Back
Top