Why won't my ASP.Net Core Web API Controller return XML?

后端 未结 8 2135
自闭症患者
自闭症患者 2020-12-14 08:28

I have the following simple Web API controller:

    // GET: api/customers
    [HttpGet]
    public async Task Get()
        {
        var         


        
8条回答
  •  有刺的猬
    2020-12-14 09:04

    For Core 2.x versions, the only thing that you need to do is to have the following code inside the ConfigureServie method of Startup.cs file.

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc()
                .AddMvcOptions(o => o.OutputFormatters.Add(
                  new XmlDataContractSerializerOutputFormatter()));
    }
    

    You need to reference the Microsoft.AspNetCore.Mvc.Formatters.

提交回复
热议问题