Though I have read some WCF articles about message contract, but I am not able to comprehend what is the real use of message contract. Can I use MessageContract
instead of DataContract
or in complement to DataContract
?
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.
No, the DataContractAttribute is not required - WCF will infer serialization rules.
WCF has five types of contracts: service contract, operation contract, data contract, message contract and fault contract.
A DataContract is a description of a type that is exposed and supported by your service. A MessageContract is an abstraction over a SOAP message that allows you to explicitly dictate the structure of the underlying message.
They are meant to compliment each other and serve different purposes.
Marc Gravell answered to a similar question WCF: MessageContract, DataContract ... Confused?
One of the advantages of message-contracts is that you can set privacy against members, but in many cases this isn't necessary. In such cases, I prefer to keep the contract as simple as possible, just as a data-contract.
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