title: Deserializing XML From Rest service
body: <p>I am having trouble deserializing a Rest XML response into its object. If I serialize the data contract that I am expecting in the consumer application, the XML formatting is slightly different than what is actually being received from the Rest service. The data contract class that is sent from the service is the exact same as the one that I am expecting. If I change the XML received from the Rest service to the response expected by the consumer application, everything works.</p>
  
  <p>The response that I am receiving from the Rest service is below.</p>
  
  <pre><code>&lt;GeneralInquiryResponseCollection xmlns=\"http://schemas.datacontract.org/2004/07/MEA.SmartApp.AdminGateway.ServiceContract.Responses\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"&gt;
    &lt;ResultCode i:nil=\"true\"/&gt;
    &lt;ResultCodeDescription i:nil=\"true\"/&gt;
    &lt;ResultInfoDescription i:nil=\"true\"/&gt;
    &lt;ErrorMessage/&gt;
    &lt;IsSuccess&gt;true&lt;/IsSuccess&gt;
    &lt;TransactionStatus&gt;
      &lt;Description&gt;Transaction Successful&lt;/Description&gt;
      &lt;StatusCode&gt;2000&lt;/StatusCode&gt;
    &lt;/TransactionStatus&gt;
    &lt;AsOfDate&gt;9999-12-31T00:00:00&lt;/AsOfDate&gt;
    &lt;FunctionalGroupingCode&gt;302&lt;/FunctionalGroupingCode&gt;
    &lt;GeneralInquiryResponseContainer&gt;
    &lt;/GeneralInquiryResponseContainer&gt;
    &lt;LastWMAValuationDate&gt;0001-01-01T00:00:00&lt;/LastWMAValuationDate&gt;
    &lt;PolicyNumber&gt;551372461&lt;/PolicyNumber&gt;
    &lt;TransactionExecutionDateTime&gt;2014-01-14T15:05:05.859558&lt;/TransactionExecutionDateTime&gt;
  &lt;/GeneralInquiryResponseCollection&gt;
  </code></pre>
  
  <p>The XML that I get when I serialize from the expected data contract is below.</p>
  
  <pre><code>&lt;?xml version=\"1.0\"?&gt;
  &lt;GeneralInquiryResponseCollection xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"&gt;
    &lt;ResultCode /&gt;
    &lt;ResultCodeDescription&gt;Success&lt;/ResultCodeDescription&gt;
    &lt;ResultInfoDescription&gt;Result Info Description&lt;/ResultInfoDescription&gt;
    &lt;IsSuccess&gt;true&lt;/IsSuccess&gt;
    &lt;TransactionStatus&gt;
      &lt;Description&gt;Transaction Successful&lt;/Description&gt;
      &lt;StatusCode&gt;2000&lt;/StatusCode&gt;
      &lt;HTTPStatusCode&gt;OK&lt;/HTTPStatusCode&gt;
    &lt;/TransactionStatus&gt;
    &lt;StatusCode&gt;2000&lt;/StatusCode&gt;
    &lt;AsOfDate&gt;9999-12-31T23:59:59.9999999&lt;/AsOfDate&gt;
    &lt;FunctionalGroupingCode&gt;302&lt;/FunctionalGroupingCode&gt;
    &lt;LastWMAValuationDate&gt;0001-01-01T00:00:00&lt;/LastWMAValuationDate&gt;
    &lt;PolicyNumber&gt;551372461&lt;/PolicyNumber&gt;
    &lt;TransactionExecutionDateTime&gt;2014-01-14T14:40:59.0930535-07:00&lt;/TransactionExecutionDateTime&gt;
  &lt;/GeneralInquiryResponseCollection&gt;
  </code></pre>
  
  <p>The main differences between them are as follows.</p>
  
  <ol>
  <li><p>Consumer expects - 
  <code>&lt;?xml version=\"1.0\"?&gt;</code> - but Rest service does not send this.</p></li>
  <li><p>Consumer expects - <code>&lt;GeneralInquiryResponseCollection xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"&gt;</code></p></li>
  </ol>
  
  <p>Rest service sends <code>&lt;GeneralInquiryResponseCollection xmlns=\"http://schemas.datacontract.org/2004/07/MEA.SmartApp.AdminGateway.ServiceContract.Responses\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"&gt;</code></p>
  
  <ol>
  <li>Consumer expects that properties of null value does not have the tag in the XML, but the Rest service sends the tag with i:nil=\"true\".</li>
  </ol>
  
  <p>The code that deserializes is below where T is a GeneralInquiryResponseCollection.</p>
  
  <pre><code>using (var ResponseStream = Response.GetResponseStream())
  {
      XmlSerializer Serializer = new XmlSerializer(typeof(T));
      return (T)Serializer.Deserialize(ResponseStream);
  }
  </code></pre>
  
  <p>Below is the service contract</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Runtime.Serialization;
  using MEA.SmartApp.AdminGateway.Interfaces;
  
  namespace MEA.SmartApp.AdminGateway.ServiceContract.Responses
  {
      [DataContract]
      public class GeneralInquiryResponseCollection : WMAResponse, IWMAResponse
      {
  
          #region Data Members
  
          [DataMember]
          public DateTime AsOfDate { get; set; }
  
          [DataMember]
          public string FunctionalGroupingCode { get; set; }
  
          [DataMember]
          public List&lt;GeneralInquiryResponse&gt; GeneralInquiryResponseContainer { get; set; }
  
          [DataMember]
          public DateTime LastWMAValuationDate { get; set; }
  
          [DataMember]
          public string PolicyNumber { get; set; }
  
          [DataMember]
          public DateTime? TransactionExecutionDateTime { get; set; }
  
          #endregion
      }
  }
  </code></pre>
  
  <p>GeneralInquiryResponse</p>
  
  <pre><code>using System;
  using System.Runtime.Serialization;
  using System.Xml.Serialization;
  using MEA.SmartApp.AdminGateway.Interfaces;
  
  namespace MEA.SmartApp.AdminGateway.ServiceContract.Responses
  {
      [DataContract(Namespace = "")]
      [XmlInclude(typeof(ClientResponse))]
      [XmlInclude(typeof(ClientRoleResponse))]
      [XmlInclude(typeof(DCAFundResponse))]
      [XmlInclude(typeof(DCAResponse))]
      [XmlInclude(typeof(GMABResponse))]
      [XmlInclude(typeof(GMDBResponse))]
      [XmlInclude(typeof(GMIBResponse))]
      [XmlInclude(typeof(GWBResponse))]
      [XmlInclude(typeof(InterestRateResponse))]
      [XmlInclude(typeof(MoneyFundSegmentResponse))]
      [XmlInclude(typeof(MRDFundResponse))]
      [XmlInclude(typeof(PayoutFundResponse))]
      [XmlInclude(typeof(PayoutResponse))]
      [XmlInclude(typeof(PolicyFundResponse))]
      [XmlInclude(typeof(PolicyResponse))]
      [XmlInclude(typeof(PremiumBonusTransactionHistoryResponse))]
      [XmlInclude(typeof(ProducerGroupSegmentResponse))]
      [XmlInclude(typeof(RebalancingResponse))]
      [XmlInclude(typeof(RebalancingScheduledFundResponse))]
      [XmlInclude(typeof(RebalancingUnscheduledFundResponse))]
      [XmlInclude(typeof(WithdrawalGrossTransactionHistoryResponse))]
      [XmlInclude(typeof(WithdrawalSurrenderTransactionHistoryResponse))]
      public abstract class GeneralInquiryResponse : IGeneralInquiryResponse
      {
          #region Data Members
  
          [DataMember]
          public string ResponseIdentifier { get; set; }
  
          #endregion
      }
  }
  </code></pre>
  
  <p>Ive been struggling with this one for a while and Im hitting dead ends. Any suggestions?</p>