Xml – ASP.NET Core 1.0 Web API doesn’t return XML

asp.net-coreasp.net-web-apicontent-typexml

How can I have my vnext API to return XML and JSON ?

I thought that using content-type with application/xml would work as it was before.
Note that I tryed with Accept : application/xml too.

But it seems not.

EDIT :

this is my project.json file :

{
  "webroot": "wwwroot",
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
    "Microsoft.AspNet.Mvc": "6.0.0-beta4",
    "Microsoft.AspNet.Mvc.Xml": "6.0.0-beta4"
  },

  "commands": {
      "web": "Microsoft.AspNet.Hosting --server     Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ]
}

this is my startup.cs :

public class Startup
{
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
        services.ConfigureMvc(options =>
        {
            //options.AddXmlDataContractSerializerFormatter();

            options.InputFormatters.Add(new XmlSerializerInputFormatter());
            options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
        });
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseMvc();
    }
}

Best Solution

Updated details following release of .Net Core 1.0.0

startup.cs

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddMvc(config =>
    {
        // Add XML Content Negotiation
        config.RespectBrowserAcceptHeader = true;
        config.InputFormatters.Add(new XmlSerializerInputFormatter());
        config.OutputFormatters.Add(new XmlSerializerOutputFormatter());
    });

project.json

"dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.0.0",

For more help see Shawn Wildermuths blog post on the subject: Content Negotiation in ASP.NET Core

Related Question