Part 11 Difference between datacontract and messagecontract in wcf

Published on November 23, 2017

Link for code samples used in the demo

Link for all dot net and sql server video tutorial playlists

DataContract gives very limited control over the SOAP messages. DataContract allows us to control the Name and Order of XML elements in the body section of the SOAP message. Beyond this we don’t have much control over the SOAP messages.

On the other hand, MessageContract gives full control over the SOAP messages by providing access to the SOAP header and body sections using MessageHeader and MessageBodyMember attributes. Use MessageContract if there is a reason to tweak the structure of the soap XML i.e if you want to include any additional information in the SOAP header.

WCF Interview Questions related to MessageContract that were asked in an interview attended by one our youtube subscribers
1. Why do use MessageContract in WCF?
MessageContract gives full control over the SOAP messages. For example, it allows us to include custom information in the SOAP header.

2. What kind of custom information?
User credentials to invoke the service

3. Why do you need to pass user credentials in the header? Can’t you pass them as method parameters?
We can, but user credentials are periphery to what the method has to do. So, it would make more sense to pass them out of band in the header, rather than as additional parameters.

4. SOAP messages are in xml format, so anyone can read the credentials? How you do you protect sensitive data?
Using MessageContract we can sign and encrypt messages. Use ProtectionLevel named parameter.

https://cafeadobro.ro/

https://www.stagebox.uk/wp-includes/depo10-bonus10/

depo 25 bonus 25

https://parfumschristianblanc.com/

https://www.barplate.com/wp-includes/js/qris/

https://hotmusic507.org/

Enjoyed this video?
"No Thanks. Please Close This Box!"