C# – Is DataContract attributes required for WCF

cnetserializationwcf

I'm writing WCF service and his client. I want to send/receive objects of my custom classes, between service and client.

I have 3 modules

  • WCF service
  • WCF client
  • common class library

Both WCF service and client have references to common class library.
I don't want to mark all my class with DataContract attributes.

So, my question "Is DataContract attributes required for WCF?"

I use .NET 4 and netTcpBinding.

Best Answer

If I recall correctly(IIRC), if you don't use formal data-contract markers, it defaults to acting like a field-serializer. This will work, but is less easy to version, since private changes can break the client/server. IMO you should always formally decorate WCF types with the data-contract/data-member attributes. It will work without them, but for the wrong reasons (IIRC, originally it didn't work without formal markers).