问题
I am using the following to make a call to a WebAPI
using (HttpClient client = HttpClientFactory.Create(new AuthorisationHandler()))
{
client.BaseAddress = new Uri(BaseURI);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
var httpResponseMessage = await client.PostAsXmlAsync<AvailRequest>("Avail/Search/", req);
httpResponseMessage.EnsureSuccessStatusCode();
var availResp = await httpResponseMessage.Content.ReadAsAsync<AvailResponse>();
return availResp;
}
the AvailResponse class looks something like this
[DataContract(Namespace = "")]
public class AvailResponse
{
[DataMember]
public ICollection<NotWorkingType> NotWorking { get; set; }
[DataMember]
public ICollection<WorkingType> Working { get; set; }
}
for some reason - clearly unknown to me - when the response comes in and is parsed into the AvailResponse
object only the WorkingType
is de-serialised and the other NotWorking
one is not. I have used fiddler and can confirm that the response has both these in i.
I have tried using a XmlMediaTypeFormatter
in place of the default and even setting the UseXmlSerialiser
to true, but to no avail.
could someone shed some light on what is going on please
I would have thought that if it is not going to deserialise properly it would chuck and error rather than simply deserialising a part of the response.
any help as ever much appreciated
thanks
nat
来源:https://stackoverflow.com/questions/24428974/httpclient-readasasynctype-only-deserializing-part-of-the-response