Can anyone please tell me when should I use MessageContracts and when should I use DataContracts and why ? As I write my wcf service , I always use DataContract but don't know the use of MessageContracts . Please someone elaborate..
A message contract is used to control the structure of a message body and serialization process. It is used to send/access the information in the soap header. By use of a Message Contract we can customize the parameters sent using a SOAP message between the client and the server.
A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. That is, to communicate, the client and the service do not have to share the same types, only the same data contracts.
Use Message Contracts when you need more control. In particular, to specify Headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With