michael
michael

Reputation: 15302

DataContract vs Serializable -- Do either really matter if you want to serialize as efficient (custom binary) as possible?

Basically, if I mark my classes as [DataContract] can I still write my own serializer that extends from XmlObjectSerializer that returns a binary the same way as I could if I did [Serializable]?

Upvotes: 1

Views: 514

Answers (1)

carlosfigueira
carlosfigueira

Reputation: 87308

Yes you can, but remember that the serializer, if inheriting from XmlObjectSerializer will have to deal with XML. Which XML writer / reader you use will determine whether you're using a binary representation or not. One "binary" XML reader/writer is the one created by XmlDictionaryReader.CreateBinaryReader and XmlDictionaryWriter.CreateBinaryWriter.

The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/29/wcf-extensibility-icontractbehavior.aspx has a sample which shows a custom XmlObjectSerializer which, if used with a binary XML writer, can serialize objects to a fairly small size.

Upvotes: 1

Related Questions