title: Deserialize xml to object from webapi
body: <p>For reasons I wont' go into here, I can't use the object type as a parameter into my webapi controller.  Therefore, I need to figure out a way to deserialize the xml object into my c# object using XmlDocument, or something similar.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>    public void Post(HttpRequestMessage request)
      {
          var xmlDoc = new XmlDocument();
          xmlDoc.Load(request.Content.ReadAsStreamAsync().Result);
          using (XmlReader xmlReader = new XmlNodeReader(xmlDoc))
          {
              Object obj = new XmlSerializer(typeof(myObject)).Deserialize(xmlReader);
              myObject scp = (myObject)obj;
          } 
      }
  </code></pre>
  
  <p>unfortunately that's throwing errors.  Can anyone provide some suggestion as to how I can deserialize my xml into my object?</p>
  
  <p>tia</p>
  
  <p>Edit: here's the xml I'm trying to deserialize:</p>
  
  <pre><code>&lt;Student&gt;
  &lt;studentid&gt;1234&lt;/studentid&gt;
  &lt;command&gt;post&lt;/command&gt;
  &lt;posttype&gt;charge&lt;/posttype&gt;
  &lt;transaction_description&gt;This is a test post to the web api&lt;/transaction_description&gt;
  &lt;payment_type&gt;CC&lt;/payment_type&gt;
  &lt;term_code&gt;2013SPRING&lt;/term_code&gt;
  &lt;amount&gt;432.75&lt;/amount&gt;
  &lt;/Student&gt;
  </code></pre>
  
  <p>and here's the error I'm getting:</p>
  
  <blockquote>
    <p>System.InvalidOperationException:  was not expected.
    Generated: Wed, 19 Mar 2014 20:18:58 GMT</p>
    
    <p>System.InvalidOperationException: There is an error in XML document
    (1, 2). ---> System.InvalidOperationException:  was
    not expected.    at
    Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderStudentChargePost.Read3_StudentChargePost()
    --- End of inner exception stack trace ---    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
    xmlReader, String encodingStyle, XmlDeserializationEvents events)<br>
    at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)<br>
    at
    CashNetSSO.Controllers.API.StudentInformationPostController.Post(HttpRequestMessage
    request) in
    C:\Projects\CashNetSSO\Development\CashNetSSO\CashNetSSO\Controllers\API\StudentInformationPostController.cs:line
    23    at lambda_method(Closure , Object , Object[] )    at
    System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;>c_<em>DisplayClassf.b</em>_9(Object
    instance, Object[] methodParameters)    at
    System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object
    instance, Object[] arguments)    at
    System.Web.Http.Controllers.ReflectedHttpActionDescriptor.&lt;>c_<em>DisplayClass5.b</em>_4()
    at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1
    func, CancellationToken cancellationToken)</p>
  </blockquote>