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 Accep
This is simplified in RC2 to just services.AddMvc().AddXmlDataContractSerializerFormatters();
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.AddMvc().AddXmlDataContractSerializerFormatters();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
MVC 6 RespectBrowserAcceptHeader is false by default. Hence it will bypass the content negotiation. And that's why probably you're getting XML always after enabling the XML formatter.
You can turn the RespectBrowserAcceptHeader to true by adding the following to your startup file:
services.Configure<MvcOptions>(options =>
{
options.RespectBrowserAcceptHeader = true;
});