Why won't my ASP.Net Core Web API Controller return XML?
<p>I have the following simple Web API controller:</p>
<pre><code>    // GET: api/customers
    [HttpGet]
    public async Task&lt;IActionResult&gt; Get()
        {
        var customers = await uow.Users.GetAllAsync();
        var dto = customers.Select(p =&gt; new CustomerDto {Id = p.Id, Email = p.Email, UserName = p.UserName});
        return Ok(dto); // IEnumerable&lt;CustomerDto&gt;
        }
</code></pre>
<p>In Postman, I'm setting the Accept header to <code>application/xml</code>, but no matter what I try, I can only get JSON data back.</p>
<p><a href="https://i.stack.imgur.com/D3Sjt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/D3Sjt.png" alt="Postman screen shot" /></a></p>
<p>I read somewhere that in order to get XML, I must add <code>[DataContract]</code> and <code>[DataMember]</code> attributes to my DTO, which now looks like this:</p>
<pre><code>[DataContract]
public class CustomerDto
    {
    [DataMember]
    public string Id { get; set; }

    [Required]
    [EmailAddress]
    [Display(Name = &quot;Email&quot;)]
    [DataMember]
    public string Email { get; set; }

    [Required]
    [Display(Name = &quot;Login Name&quot;)]
    [DataMember]
    public string UserName { get; set; }
    }
</code></pre>
<p>I've been at it several hours now and I'm just not seeing why it doesn't work. I've tried:</p>
<ul>
<li><p>Making the action method synchronous and asynchronous</p>
</li>
<li><p>Returning the data directly, and setting the return type to <code>IEnumerable&lt;CustomerDto&gt;</code></p>
</li>
<li><p>Converting the collection to an array instead of a list</p>
</li>
<li><p>Returning an <code>IActionResult</code></p>
</li>
<li><p>Returning a single item, instead of a collection</p>
</li>
<li><p>I've verified that the Accept header is showing up in the request by examining it in the debugger.</p>
</li>
<li><p>Lots of &quot;Googling with Bing&quot; and reading various blogs</p>
</li>
<li><p>Creating a new WebAPI project from the template and seeing if there is any inspiration there (not really).</p>
<p>I expect it's simple, but I can't see it...</p>
</li>
</ul>