Content negotiation in WEB API without DataContract

115 views Asked by At

How do I make HttpResponseMessage follow xml schema rather then datacontract?

i tried to do

return new HttpResponseMessage()
{
     StatusCode = HttpStatusCode.OK,
     Content = new ObjectContent<Foo>(foo, Configuration.Formatters.XmlFormatter)

};

but that did not do the trick.

Also if I do this, Action would always serve xml and would not do content negotiation. I tried to add List as a param, but HttpResponseMessage does not expect a list, just a single item.

Is there a way to allow content negotiation without use of DataContract? Basically now HttpResponseMessage is ignoring xml schema.

1

There are 1 answers

0
mko On BEST ANSWER

I guess the answer to this is to use

GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true;