Today I Learned #0

This is Today I Learned – some nice things I learned, too short to be valid blog post, but too important/interesting/etc to not be written down

While exposing classes to WCF service, you have to use [DataContract] (for class) and [DataMember] (for properties) attributes. Or do you?

Turns out that around 3.5 you don’t have to do it. If you provide class with no attributes it will work out of the box! Where’s the catch? There are two:

  1. You will lose some of features, like naming, being able to serialize private properties, declaring something as required. While some can be more useful than others in specific scenarios – just ask yourself – should you really send private data? 😉
  2. And this is important! If you dare to use [DataMember] on some properties – only those will be serialized.

Leave a Reply

Your email address will not be published. Required fields are marked *