homepage/_posts/2017-04-08-today-i-learned-0.md
2020-04-02 10:54:30 +02:00

1.1 KiB

ID post_title author post_excerpt layout permalink published post_date
90 Today I Learned #0 dreat post http://dreat.info/2017-04-08-today-i-learned-0/ true 2017-04-08 07:00:54

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.