HttpClient ReadAsAsync<Type> only deserializing part of the response

谁说我不能喝 提交于 2020-01-07 03:27:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!