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

Popular posts from this blog

Accessing Dynamics NAV OData with Postman

Error with Zetadocs on Sharepoint Online

Don't Let CRM Authentication Changes Tank Your Integration