jeudi 6 avril 2017

XML DeSerialization returning Null values

I plead for your urgent assistance to help solve this problem.

I have a POST method in a web api that has a RequestAppointment paramater. For example:

 // POST: api/RequestAppointment
            public HttpResponseMessage Post([FromBody]RequestAppointment httpRequest)
            {
                var response = Appointment.CreateAppointment(httpRequest);

                return Request.CreateResponse<ResponseRequest>(System.Net.HttpStatusCode.Created, response); 
            } 

RequestAppoint class has this structure:

public partial class RequestAppointment
    {
        public RequestAppointmentAppointmentInformation appointmentInformation { get; set; }      
    }
    public partial class RequestAppointmentAppointmentInformation
    {
        public string AppointmentCcEmail { get; set; }        
        public string ClaimType { get; set; }       
        public RequestAppointmentAppointmentInformationClaimant Claimant { get; set; }

    }
    public partial class RequestAppointmentAppointmentInformationClaimant
    {
        public System.DateTime DateOfBirth { get; set; }        
    }

Two requests are possible to be made: 1st one is :

<RequestAppointment>
  <appointmentInformation>
    <AppointmentCcEmail>x.x.com</AppointmentCcEmail>   
    <ClaimType>A</ClaimType>
    <Claimant>
      <DateOfBirth>1961-12-25</DateOfBirth>
    </Claimant>
  </appointmentInformation>
</RequestAppointment>

2nd Request is:

<RequestAppointment>
  <appointmentInformation>
    <AppointmentCcEmail>x.x.com</AppointmentCcEmail>   
    <ClaimType>A</ClaimType>   
  </appointmentInformation>
</RequestAppointment>

The difference between the two request XML is that #1 has Claimant tag while the #2 does not have.

The 2nd request does not have because the claimant is not supplied when users call the web service from data interface. While the first will always have when Claimant is supplied.

On my testing using Fiddler, my #1 request returns data. That is, it is able to deserialize into the object RequestAppointment, while #2 request returns null values.

What can I do to resolve this issue? The request will always come in those two formats and they will always use the same model structure.

What can I do to solve this issue? I tested the scenario in Fiddler.

Thanks

Aucun commentaire:

Enregistrer un commentaire