Search code examples
wcfdatacontractserializer

WCF DataContract requires Serialization?


A class that has the [DataContract] attribute, is it not automatically serialized? If not, is it a requirement to use the [Serializable] attribute (or inherit from ISerialize)?

I ask this because I have old code from a previous project that apparently the [DataContract] classes do not mention anything, explicitly, about serialization.

The ultimate question: I want a WCF operation (method) to return a DataContract class. Does the method have to explicitly serialize the class before returning it, or is it automatically serialized? I always thought it would be the latter.

Thanks!


Solution

  • No, [Serializable] is not necessary on a data contract. It is also not necessary for XML Serialization.