Any advantage to using DataContract?
A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. That is, to communicate, the client and the service do not have to share the same types, only the same data contracts.
DataContractSerializer(Type, IEnumerable<Type>) Initializes a new instance of the DataContractSerializer class to serialize or deserialize an object of the specified type, and a collection of known types that may be present in the object graph.
For an introduction to data contracts, see Using Data Contracts. When deserializing XML, the serializer uses the XmlReader and XmlWriter classes. It also supports the XmlDictionaryReader and XmlDictionaryWriter classes to enable it to produce optimized XML in some cases, such as when using the WCF binary XML format.
DataContractSerializer as the Default By default WCF uses the DataContractSerializer class to serialize data types.
See a great comparison of XmlSerializer and DataContractSerializer on Dan Rigsby's blog.
Some points in favor of DataContractSerializer:
[DataMember]
- even if it's not public
visibleOrder=
attribute on the [DataMember]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With