0

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

nat
  • 2,185
  • 5
  • 32
  • 64
  • Just in case this might help : http://stackoverflow.com/questions/2519240/wcf-datacontract-some-fields-do-not-deserialize – Jason Evans Jun 26 '14 at 11:45
  • hi jason thanks for that, presume i need to do that all the way down the hierarchy? as done the top few but still no luck.. :( – nat Jun 26 '14 at 11:57
  • Sorry that didn't work for you. I'm not sure what the explanation for your issue is exactly, I thought I'd give that link a shot :) – Jason Evans Jun 26 '14 at 12:47
  • thanks jason, appreciate your help nonetheless – nat Jun 26 '14 at 16:16

0 Answers0