A data contract is a formal agreement between a client and a service that abstractly describes the data to be exchanged. In WCF, this is the most common way to serialize an object and make it ready to be available for passing between client and service. This is done by marking the class with the [DataContract] attribute.
It is worth mentioning that the serialization is not restricted to exactly match the class name and/or the property names in the class. You can simply use the DataContract and DataMember attributes to define their names in serialization. For example, consider the following code snippet:
[DataContract (Name = "Employee")]
public class EmployeeModel { ... }
In the preceding code snippet, though the class name is EmployeeModel, the class will be exposed to serialization as Employee as the name mapping has been done using the Name property of the attribute.
[DataContract (Name = "Employee")]
public class EmployeeModel { ... }
In the preceding code snippet, though the class name is EmployeeModel, the class will be exposed to serialization as Employee as the name mapping has been done using the Name property of the attribute.