开发者

Why should I use DataContract Serializer while I have XML/Binary serializer?

Can anyone 开发者_开发技巧please elabortae me the reasons why should I use Data Contract Serializer while we have XML/Binary serializer already there in .Net ?


This is a site i found when i was looking into the same issue. You should check this out

Quoting from the same link mentioned above:

Advantages of DataContractSerializer over XMLSerializer

  1. Opt-in rather than opt-out properties to serialize.
  2. Because it is opt in you can serialize not only properties, but also fields. You can even serialize non-public members such as private or protected members. And you dont need a set on a property either (however without a setter you can serialize, but not deserialize)
  3. Is about 10% faster than XmlSerializer to serialize the data because since you don’t have full control over how it is serialize, there is a lot that can be done to optimize the serialization/deserialization process.
  4. Can understand the SerializableAttribute and know that it needs to be serialized
  5. More options and control over KnownTypes

Hope it helps!


One more HUGE advantage; DataContract serialization allows for interop between any two classes that implement the same DataContract. This is what allows WCF to generate the data classes for you automatically when you reference a WCF service. You can also "hack" this process by referencing a published DataContract in a new user-developed class (or two or three); You can then transfer data between instances of these classes, and any other new ones you create, via serialization. This is also possible but much more difficult with XML serialization, and impossible with binary serialization.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜