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:
- 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? 😉
- And this is important! If you dare to use [DataMember] on some properties – only those will be serialized.