title: Call API return XML, how to use XmlSerializer to Deserialize the file to object?
body: <p>Recently I spent quite some time on these, and want to write down some notes, hopefully it helps.
  Step 1: Make the API call, notice the contentType is: "application/xml" 
  you can check Sample code below.<br>
  Step 2: The tricky part is how to create the class of "myObject".<br>
          If the object is not completely matching the XML return, then you will always get XML deserialize error and have no clue.  </p>
  
  <p>Check my answer below for creating .cs class which could correct deserialize.</p>
  
  <pre><code>try
              {
                  byte[] bHeaderBytes = System.Text.Encoding.UTF8.GetBytes(GetUserPasswordString());
                  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(cRequestString);
                  request.Method = WebRequestMethods.Http.Get;
                  request.PreAuthenticate = true;
                  request.ContentType = "application/xml";
                  request.Accept = "application/xml";
                  request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(bHeaderBytes));
                  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                  XmlDocument xmlDoc = new XmlDocument();
                  xmlDoc.Load(response.GetResponseStream());                                                           
                  XmlNodeReader xReader = new XmlNodeReader(xmlDoc.DocumentElement);           
                  return (myObject)xSerializer.Deserialize(xReader);                
              }
              catch
              {
                  return null;
              }     
  </code></pre>