title: WebAPI Serialization problems when consuming Recurly Rest API which returns XML
body: <p>I'm new to the ASP.Net Web API. I'm trying to interact with the Recurly REST based API and I am getting errors like below during my ReadAsAsync call which is the point I believe it attempts to serialize the response.</p>
  
  <pre><code>{"Error in line 1 position 73. Expecting element 'account' from namespace 'http://schemas.datacontract.org/2004/07/RecurlyWebApi.Recurly'.. Encountered 'Element'  with name 'account', namespace ''. "}
  </code></pre>
  
  <p>Here is my HttpClient implementation, simplified for brevity:</p>
  
  <pre><code>  public class RecurlyClient
    {
      readonly HttpClient client = new HttpClient();
  
      public RecurlyClient()
      {
        var config = (RecurlySection)ConfigurationManager.GetSection("recurly");
  
        client.BaseAddress = new Uri(string.Format("https://{0}.recurly.com/v2/", config.Subdomain));
  
        // Add the authentication header
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(config.ApiKey)));
  
        // Add an Accept header for XML format.
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
      }
  
      public T Get&lt;T&gt;(string id)
      {
        var accounts = default(T);
  
        // Make the request and get the response from the service
        HttpResponseMessage response = client.GetAsync(string.Concat("accounts/", id)).Result;  // Blocking call!
  
        if (response.IsSuccessStatusCode)
        {
          // Parse the response body. Blocking!
          accounts = response.Content.ReadAsAsync&lt;T&gt;().Result;
        }
  
        return accounts;
      }
    }
  </code></pre>
  
  <p>And here is my model:</p>
  
  <pre><code>  [XmlRoot("account")]
    public class Account
    {
      [XmlAttribute("href")]
      public string Href { get; set; }
  
      [XmlElement("account_code")]
      public string AccountCode { get; set; }
  
      [XmlElement("state")]
      public AccountState State { get; set; }
  
      [XmlElement("username")]
      public string Username { get; set; }
  
      [XmlElement("email")]
      public string Email { get; set; }
  
      [XmlElement("first_name")]
      public string FirstName { get; set; }
  
      [XmlElement("last_name")]
      public string LastName { get; set; }
  
      [XmlElement("company_name")]
      public string Company { get; set; }
  
      [XmlElement("accept_language")]
      public string LanguageCode { get; set; }
  
      [XmlElement("hosted_login_token")]
      public string HostedLoginToken { get; set; }
  
      [XmlElement("created_at")]
      public DateTime CreatedDate { get; set; }
  
      [XmlElement("address")]
      public Address Address { get; set; }
    }
  </code></pre>
  
  <p>And an example of the XML response from the service:</p>
  
  <pre><code>&lt;account href="https://mysubdomain.recurly.com/v2/accounts/SDTEST01"&gt;
    &lt;adjustments href="https://mysubdomain.recurly.com/v2/accounts/SDTEST01/adjustments"/&gt;
    &lt;invoices href="https://mysubdomain.recurly.com/v2/accounts/SDTEST01/invoices"/&gt;
    &lt;subscriptions href="https://mysubdomain.recurly.com/v2/accounts/SDTEST01/subscriptions"/&gt;
    &lt;transactions href="https://mysubdomain.recurly.com/v2/accounts/SDTEST01/transactions"/&gt;
    &lt;account_code&gt;SDTEST01&lt;/account_code&gt;
    &lt;state&gt;active&lt;/state&gt;
    &lt;username&gt;myusername&lt;/username&gt;
    &lt;email&gt;simon@example.co.uk&lt;/email&gt;
    &lt;first_name&gt;First name&lt;/first_name&gt;
    &lt;last_name&gt;Last name&lt;/last_name&gt;
    &lt;company_name&gt;My Company Name&lt;/company_name&gt;
    &lt;vat_number nil="nil"&gt;&lt;/vat_number&gt;
    &lt;address&gt;
      &lt;address1&gt;My Address Line 1/address1&gt;
      &lt;address2&gt;My Address Line 2&lt;/address2&gt;
      &lt;city&gt;My City&lt;/city&gt;
      &lt;state&gt;My State&lt;/state&gt;
      &lt;zip&gt;PL7 1AB&lt;/zip&gt;
      &lt;country&gt;GB&lt;/country&gt;
      &lt;phone&gt;0123456789&lt;/phone&gt;
    &lt;/address&gt;
    &lt;accept_language nil="nil"&gt;&lt;/accept_language&gt;
    &lt;hosted_login_token&gt;***&lt;/hosted_login_token&gt;
    &lt;created_at type="datetime"&gt;2013-08-22T15:58:17Z&lt;/created_at&gt;
  &lt;/account&gt;
  </code></pre>