XML formatting serializes controller responses as XML when ASP.NET Core MVC has an XML formatter available and content negotiation selects it. Add XML support alongside JSON in Program.cs: AddControllers().AddNewtonsoftJson().AddXmlDataContractSerializerFormatters(). section 20.4.2
Account for these practical behaviors:
- Return an XML-serializable object such as ProductBindingTarget rather than an Entity Framework Core entity with interface-based navigation properties. section 20.4.2
Requesting XML
Invoke-WebRequest http://localhost:5000/api/content/object -Headers @{Accept="application/xml"} returns Content-Type application/xml; charset=utf-8 and a ProductBindingTarget element containing Name, Price, CategoryId, and SupplierId.
