title: How to return Xml rather than JSON from a Web API Action?
body: <p>How to configure the actions within a Web API Controller, to return XML rather than JSON?</p>
  
  <p>I have an action which returns a UserProfile object which has XmlElement attributes:</p>
  
  <pre><code>[HttpGet]
          public UserProfile SearchByEmail(string siteName, string email)
          {
              var userProfile = this._profileFinderByEmail.Find(siteName, email);
  
              if (userProfile == null)
              {
                  throw new HttpResponseException(HttpStatusCode.NotFound);
              }
  
              return userProfile;
          }
  </code></pre>
  
  <p>When when I run this action, it returns application/json rather than xml. How could I return xml?</p>
  
  <p>Judging by Fiddler the request header that I was sending had the below Accept header key:</p>
  
  <pre><code>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  </code></pre>
  
  <p>that I expected it to return xml but it doesn't.</p>
  
  <p>How to fix it?</p>
  
  <p>I've also set the below value in the WebApiConfig class:</p>
  
  <pre><code>GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true;
  </code></pre>
  
  <p>Viewing from Chrome/Network tab, I can see the below error:</p>
  
  <pre><code>Status Code:406 Not Acceptable
  </code></pre>