This project is read-only.

Serialising POCO's

Topics: Web Api
May 9, 2011 at 4:58 PM


When trying to create a WebAPI or REST API I work a lot with POCO classes to represent the request and responce data types. Now with WCF and SOAP then the DataContract serializer was the prefered attribute to use on these classes. What about now, with Web API. It seems to me that its all about having a well defined XML structure, so should I now be using the XmlSerializer.

I don't like to not use anything as I want to be explicit in the definitions, hopefully preventing later releases of the framework from altering my services.

Thanks for your help


May 10, 2011 at 4:08 PM

Hi Graham,

In WCF Web API the serialization is a little bit more flexible allowing you to plug in your own custom serializers if you want. By default, you would be correct, you use the XmlSerializer's attributes on your POCOs. If you wanted to use your own serializer you could create a MediaTypeFormatter with the right content types.