- First, let's add the following dependency in the project:
"Microsoft.AspNetCore.MVC.Formatters.Xml": "2.0.0"
- Next, let's add the following code to the ConfigureServices method of Startup.cs:
services.AddMVC(options =>{ options.RespectBrowserAcceptHeader = true; options.InputFormatters.Add( new XmlDataContractSerializerInputFormatter()); options.OutputFormatters.Add( new XmlDataContractSerializerOutputFormatter());});
- Finally, we can see the list of products in the XML format: