Adding XML Formatting to a Web API Controller
A .NET API project will return JSON by default but sometimes you need something else. By adding a new input and output formatter, you can accomplish this. The ConfigureServices function in the Startup.cs file can be changed with the following code:
services.AddMvc(options =>
{
options.InputFormatters.Add(new XmlSerializerInputFormatter(options));
options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
options.OutputFormatters.Add(new StringOutputFormatter());
});
You will also need to be using Microsoft.AspNetCore.Mvc.Formatters.
Comments
Post a Comment