3

Prior to the asp.net 4 RC update, I had been using the WebApi for outputting XML. My model had XmlSerialization attributes [XmlElement(ElementName = "the name")] so that I could use friendlier names.

e.g.

[XmlElement(ElementName = "Branch")]
public string site_nm { get; set; }

After the .net 4 RC update, the XML which is output ignores this.

I know that some things have changed in the WebApi, like to make a method return values based on OData protocols when returning IQueryable<T>, you now need to add [Queryable] to your methods.

Is there something that I need to add to make the serialization work? I have read through change notes but can't see anything.

Tim B James
  • 20,084
  • 4
  • 73
  • 103

1 Answers1

5

You need to instruct the formatter to use XmlSerializer:

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

The default now is the DataContractSerializer.

Aliostad
  • 80,612
  • 21
  • 160
  • 208