title: WCF Service Request is Null when using XmlSerializerFormat
body: <p>I'm writing an WCF service based on the WSDL from an old soap service. I used svcutil to generate the the service contract and made a few changes to match the site I'm hosting it on, but when I call the service from a test client, the request object is coming in as null.</p>
  
  <p>The response the service is returning is also getting serialized incorrectly which I'm sure is related. But I can't figure why its not serializing and deserializing correctly.</p>
  
  <p>Here's the service contract:</p>
  
  <pre><code>[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
  [System.ServiceModel.ServiceContractAttribute(Namespace = ApuConstants.Namespace)]
  public interface IApuService
  {
      [System.ServiceModel.OperationContractAttribute(Action = "*", ReplyAction = "*")]
      [System.ServiceModel.XmlSerializerFormatAttribute(Style = System.ServiceModel.OperationFormatStyle.Rpc, Use = System.ServiceModel.OperationFormatUse.Encoded)]
      [System.ServiceModel.ServiceKnownTypeAttribute(typeof(Part))]
      [return: System.ServiceModel.MessageParameterAttribute(Name = "return")]
      Brock.Web.Apu.Response check(Brock.Web.Apu.Request request);
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)]
  public partial class Request
  {
  
      private RequestHeader headerField;
  
      private Lookup lookupField;
  
      /// &lt;remarks/&gt;
      public RequestHeader header
      {
          get
          {
              return this.headerField;
          }
          set
          {
              this.headerField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public Lookup lookup
      {
          get
          {
              return this.lookupField;
          }
          set
          {
              this.lookupField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)]
  public partial class RequestHeader
  {
  
      private string accountField;
  
      private string idField;
  
      /// &lt;remarks/&gt;
      public string account
      {
          get
          {
              return this.accountField;
          }
          set
          {
              this.accountField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string id
      {
          get
          {
              return this.idField;
          }
          set
          {
              this.idField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)]
  public partial class Part
  {
  
      private string oemField;
  
      private string hicField;
  
      private string skuField;
  
      private string descField;
  
      private int daysField;
  
      private string availField;
  
      private string branchField;
  
      private float listField;
  
      private float netField;
  
      private string typeField;
  
      private string certField;
  
      private string statusField;
  
      /// &lt;remarks/&gt;
      public string oem
      {
          get
          {
              return this.oemField;
          }
          set
          {
              this.oemField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string hic
      {
          get
          {
              return this.hicField;
          }
          set
          {
              this.hicField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string sku
      {
          get
          {
              return this.skuField;
          }
          set
          {
              this.skuField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string desc
      {
          get
          {
              return this.descField;
          }
          set
          {
              this.descField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public int days
      {
          get
          {
              return this.daysField;
          }
          set
          {
              this.daysField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string avail
      {
          get
          {
              return this.availField;
          }
          set
          {
              this.availField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string branch
      {
          get
          {
              return this.branchField;
          }
          set
          {
              this.branchField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public float list
      {
          get
          {
              return this.listField;
          }
          set
          {
              this.listField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public float net
      {
          get
          {
              return this.netField;
          }
          set
          {
              this.netField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string type
      {
          get
          {
              return this.typeField;
          }
          set
          {
              this.typeField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string cert
      {
          get
          {
              return this.certField;
          }
          set
          {
              this.certField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string status
      {
          get
          {
              return this.statusField;
          }
          set
          {
              this.statusField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)]
  public partial class ResponseHeader
  {
  
      private string statusField;
  
      private string reasonField;
  
      private string accountField;
  
      private string idField;
  
      /// &lt;remarks/&gt;
      public string status
      {
          get
          {
              return this.statusField;
          }
          set
          {
              this.statusField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string reason
      {
          get
          {
              return this.reasonField;
          }
          set
          {
              this.reasonField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string account
      {
          get
          {
              return this.accountField;
          }
          set
          {
              this.accountField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string id
      {
          get
          {
              return this.idField;
          }
          set
          {
              this.idField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)]
  public partial class Response
  {
  
      private ResponseHeader headerField;
  
      private Part[] itemsField;
  
      /// &lt;remarks/&gt;
      public ResponseHeader header
      {
          get
          {
              return this.headerField;
          }
          set
          {
              this.headerField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public Part[] items
      {
          get
          {
              return this.itemsField;
          }
          set
          {
              this.itemsField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.SoapTypeAttribute(Namespace = ApuConstants.Namespace)]
  public partial class Lookup
  {
  
      private string oemField;
  
      private string hicField;
  
      private int qtyField;
  
      private string zipField;
  
      /// &lt;remarks/&gt;
      public string oem
      {
          get
          {
              return this.oemField;
          }
          set
          {
              this.oemField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string hic
      {
          get
          {
              return this.hicField;
          }
          set
          {
              this.hicField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public int qty
      {
          get
          {
              return this.qtyField;
          }
          set
          {
              this.qtyField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string zip
      {
          get
          {
              return this.zipField;
          }
          set
          {
              this.zipField = value;
          }
      }
  }
  </code></pre>
  
  <p>And the Implementation:</p>
  
  <pre><code>[ServiceBehavior(Namespace = ApuConstants.Namespace)]
  public class ApuService : IApuService
  {
      private readonly IApuServiceHandler _handler;
      private readonly ISettingService _settingService;
  
      public ApuService()
      {
          _handler = EngineContext.Current.Resolve&lt;IApuServiceHandler&gt;();
          _settingService = EngineContext.Current.Resolve&lt;ISettingService&gt;();
      }
  
      public Response check(Request request)
      {
          if (Authorized(request))
              return _handler.ProcessRequest(request);
          return _handler.ErrorResponse("Invalid credentials");
      }
  
      protected bool Authorized(Request request)
      {
          if (request == null || request.header == null)
              return false;
  
          var settings = _settingService.LoadSetting&lt;ApuSettings&gt;(0);
  
          if (!string.Equals(request.header.account, settings.Username, StringComparison.InvariantCultureIgnoreCase))
              return false;
  
          if (!string.Equals(request.header.id, settings.Password))
              return false;
  
          return true;
      }
  }
  </code></pre>
  
  <p>The Configuration:</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation targetFramework="4.5.1" /&gt;
    &lt;/system.web&gt;
  
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="ApuBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;bindings&gt;
      &lt;/bindings&gt;
      &lt;services&gt;
        &lt;service name="Apu.WebService.ApuService" behaviorConfiguration="ApuBehavior"&gt;
          &lt;endpoint address="" binding="basicHttpBinding" contract="Web.Apu.IApuService" bindingNamespace="http://www.testurl.com/apu" /&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>The request received by the service (from OperationContext.Current.RequestContext.RequestMessage):</p>
  
  <pre><code>&lt;Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://localhost:15555/Plugins/Brock.Apu/Remote/ApuService.svc&lt;/To&gt;
    &lt;/s:Header&gt;
    &lt;Body&gt;
          &lt;check xmlns="http://www.testurl.com/apu"&gt;
              &lt;request&gt;
                  &lt;header&gt;
                      &lt;account&gt;apu&lt;/account&gt;
                      &lt;id&gt;apu001!&lt;/id&gt;
                  &lt;/header&gt;
                  &lt;lookup&gt;
                      &lt;hic&gt;323-01327&lt;/hic&gt;
                      &lt;oem&gt;5014351AB&lt;/oem&gt;
                      &lt;qty&gt;2&lt;/qty&gt;
                      &lt;zip&gt;85304&lt;/zip&gt;
                  &lt;/lookup&gt;
              &lt;/request&gt;
          &lt;/check&gt;
      &lt;/Body&gt;
  &lt;/Envelope&gt;
  </code></pre>
  
  <p>The Response sent by the service (which is serialized incorrectly):</p>
  
  <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
          &lt;q1:checkResponse xmlns:q1="http://www.testurl.com/apu"&gt;
              &lt;return href="#id1"/&gt;
          &lt;/q1:checkResponse&gt;
          &lt;q2:Response id="id1" xsi:type="q2:Response" xmlns:q2="http://www.testurl.com/apu"&gt;
              &lt;header href="#id2"/&gt;
          &lt;/q2:Response&gt;
          &lt;q3:ResponseHeader id="id2" xsi:type="q3:ResponseHeader" xmlns:q3="http://www.testurl.com/apu"&gt;
              &lt;status xsi:type="xsd:string"&gt;no&lt;/status&gt;
              &lt;reason xsi:type="xsd:string"&gt;Invalid credentials&lt;/reason&gt;
              &lt;account xsi:type="xsd:string"/&gt;
              &lt;id xsi:type="xsd:string"/&gt;
          &lt;/q3:ResponseHeader&gt;
      &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>