wcfdatacontractserializer

DataContracts and DataMembers


Are there any ways to tell WCF to serialize the whole class when it returns? Do I literally have to add DataMember to every property?


Solution

  • Since .NET 3.5 SP1, you don't have to do this anymore.

    If you don't have any [DataContract] and [DataMember] attributes, the DataContractSerializer class will behave like the old XmlSerializer: it will serialize all public read/write properties that are listed in the class.

    You do lose a few things in the process though:

    Read all about it in detail from Aaron Skonnard at Pluralsight.