What are the Basic Advantages of Data Contract Serializer over XML serializer ?

Both the DataContract serilizer and XML Serializer serialize object state to XML content to get interoperability done. But while comparing them, we must say that the Data Contract Serializer is much faster and high controllability than XML Serializer.

First question comes in your mind, why and how?

For example if you have 1000 data members and 1000 methods in your class and you want out of these only 47 data members and 690 methods needs to be serialized.

Now if you are using XML Serializer tag over your class, though you don’t want all thousand methods and all thousand data members should serialize and deserialize, it will serialize all 1000 members and 1000 methods. So unnecessarily we are spending time for serialization/de serialization for unwanted members.

If you are in Data Contract Serilizer, you can use specifically [DataMember] tag over required data members in your class. Like

    [DataContract]
    public class Sample
    {
       [DataMember]
       public int MyProperty { get; set; }
    }

So, only 47 data members will be serialized and deserialized, and you can save time for remaining 953 data members serialization.

Same specific tag like [OperationContract] , can be used on the required methods to save time.

Now if you talk about Control, it can be like using XML sterilizer, though some methods should not be explored/get Consumed to the client, you don’t have that control to restrict them. It can be done using DataContract Serilizer.

No comments:

Post a Comment