This division depends on your use of the WCF service:
- The internal service consumed by your own .NET systems that use the same domain model.
- An external service consumed by different platforms that do not use the same domain model.
Case 1
Serialization is the process of maintaining the state of an object. The state of an object in C # is represented by data fields.
Properties in C # are essentially methods that control the state of an object. Using them can lead to different states of deserialization objects, since the order in which the properties are set can affect the final state of the data. Other factors can lead to improper deserialization of the state if, for example, the method (set property) depends on some changing context, for example, the current DateTime.
Can you say what about encapsulation? I do not want my object to be in an invalid state, and I have to perform validation checks, integrity checks on the graph of objects, etc. Yes, you should, so we put the DataMember attributes in the details? No.
The problem is that many people mix two different things: DTO (data transfer object, WCF contract) with a domain entity. You need to make sure that the data you receive is the same data that was sent, and then make sure that you can create a valid domain from this data. The best way to achieve this is to use separate classes for the DTO and build an Entity object from them.
But most programmers are lazy, and they like to simply decorate Domain Entity with DataMemeber attributes. In this case, the Field or Prop solution depends on where your validation logic is, if your verification logic is buried in Set methods, you will have to use the details if it is extenral, you must use the fields and validate your domain object after desirialization.
PS I think that the same rules apply to any serialization process, such as a database.
In addition, I would like to mention that Silverlight cannot serialize \ deserialize private fields, because you cannot access them from the outside using reflection, and you have to make them private and use InternalsVisibleToAttribute.
Case 2
It's complicated. The focus here is on interoperability. At 99.9%, you will have separate DTO classes in this case and, most likely, many different versions to support old clients. It doesn't matter where you entered the DataMembers attributes, because you are using DTO. I will not understand this scenario because developers who work on such a large-scale system are usually quite experienced and they do not bother to read SO.