Datacontract Serializer, BinaryWriter and BinaryFormatter.
-
I tested following scenarios: 1. DataContrctSerializer with BinaryWriter, something like below, assuming datacontract serializer would use binaryformatter:
DataContractSerializer binarydc = new DataContractSerializer(typeof(Library)); XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(ms); binarydc.WriteObject(writer,o);
2. I used legacy BinaryFormatter , like below:BinaryFormatter f = new BinaryFormatter(); f.Serialize(ms, o);
Size comaparison between these two are very different for the same object. Size of legacy way of serializing is less than half of DataContract serializer. here are my questions: 1. Is there any other option on DataContract Serializer, which could further reduce size? 2. If No for #1, there is no point using DataContractSerializer, right? 3. If Yes for #1, is there a way i can set this configuration in config file, so that WCF service would use binary writer instead of default xml? Thanks.