Based on your comment, I updated WebApiConfig.cs:
public static void Register(HttpConfiguration config)
{
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
config.Formatters.Add(new XmlMediaTypeFormatter());
config.Formatters.XmlFormatter.UseXmlSerializer = true;
}
Then in the webapi where I want to reply with XML
public HttpResponseMessage GetCollections(int Id)
{
List<CollectionDTO> result = _collectionsLogic.GetCollections(Id);
IContentNegotiator negotiator = this.Configuration.Services.GetContentNegotiator();
ContentNegotiationResult resultFormatted = negotiator.Negotiate(
typeof(List<CollectionDTO>), this.Request, this.Configuration.Formatters);
if (result == null)
{
var response = new HttpResponseMessage(HttpStatusCode.NotAcceptable);
throw new HttpResponseException(response);
}
return new HttpResponseMessage()
{
Content = new ObjectContent<List<CollectionDTO>>(
result,
resultFormatted.Formatter,
resultFormatted.MediaType.MediaType
)};
}
}
If I call this webapi with Postman, for example, and I insert in the header Accept equals application/xml, I receive the result in XML format, otherwise in json