2

I am reading about MessageContract & MessageHeader and trying to understand the use case of sending some info in MessageHeader and not use it just as a function parameters?

Silverlight Student
  • 3,968
  • 10
  • 37
  • 53

2 Answers2

1

Message contracts and message headers are somewhat advanced concepts which most people will never need to use. They're mostly used in interoperability scenarios where you need to communicate with a 3rd party service which expects the data in a certain format (i.e., some parameters in the headers).

Other possible scenarios for passing some parameters in message headers:

  • Headers can be easily accessed in message inspectors and other extensibility points in WCF (since headers are always buffered), so if you want to use some of those to do some validation (for example, some authentication decision), you may want to have the parameter in the header
  • As @Vasile mentioned, if you want to have a streamed transfer, since the headers are always buffered they can be used to convey some additional information to the operation prior to the (streamed) body being read / consumed
carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
0

The MessageContract & MessageHeader provides lower-level control of your messages than DataContract & DataMember. Also it provides a way to create SOAP Headers if you're using webHttpBinding or basicHttpBinding. If you're using streaming capabilities in your WCF service, than using MessageHeader is the only way to pass data besides the stream itself.
You can read more about message contracts in this MSDN article

Vasea
  • 5,043
  • 2
  • 26
  • 30
  • Sorry I am having hard time getting my head around this concept. What will be the use case of sending Operation and TransactionDateTime in message header and not in message body? Are there any limitation of sending this info in message body? – Silverlight Student Jul 25 '11 at 20:37