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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
since you don’t have
[DataMember]attributes, you cannot define an order of the fields anymore – they’ll be serialized in the order of appearanceyou cannot omit a public property (since that would require
[DataMember]on all other properties/fields)you cannot define a property to be
Required(that would be on the[DataMember]attribute again)your class now needs to have a public, parameter-less constructor (usually not needed for data contracts)
Read all about it in detail from Aaron Skonnard at Pluralsight.