I'm having some problem deserializeing a HttpResponseMessage into an object. The problem is that when the object should have deserialized all fields are null, no exceptions are thrown.
HttpContent content = new StringContent(xml);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml");
HttpResponseMessage response = await client.PostAsync("URL", content).ConfigureAwait(false);
// Parse response
if (response.IsSuccessStatusCode)
{
XmlSerializer serializer = new XmlSerializer(typeof(ResponseObject));
Stream responseStream = await response.Content.ReadAsStreamAsync();
ResponseObject responseObject = serializer.Deserialize(responseStream) as ResponseObject;
//Possible example of wrong data
Console.WriteLine(responseObject.Message);
}
[XmlRoot("response")]
public class ResponseObject
{
[XmlElement("session")]
public string Session { get; set; }
[XmlElement("status")]
public string Status { get; set; }
[XmlElement("message")]
public string Message { get; set; }
}
Response message as a string
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<response>
<val n=\"session\">SESSION ID</val>
<val n=\"status\">201</val>
<val n=\"message\">Created</val>
</response>"
Have I missed something? I'm pretty new to serializing/deserializing. Grateful for pointers.
nof tagval.