Thursday, 2 October 2014

ASP.NET WebAPI to return XML instead of the default JSON



In my WebApiConfig I have



var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);


So all the API's come back as JSON.


There is 1 API call that I need to return XML ..


This is what it have now for my return



return XDocument.Load(savedXMLFileFromServer);


but it comes back as JSON


Is there anyway to have it come back as XML


Thanks.


No comments:

Post a Comment