Adding a messageheader (on the client) to a message can be done using several methods:
- in a MessageInspector
- in the requestchannel of a custom channel
- before calling the operation on a service by adding a messageheader to the OperationContact
- in a MessageContract, we can put a MessageHeader atrtibute above a class member (which represents our custom header)
I've tried all four methods, but the first three of them seem to always use the DataContractSerializer to serialize the header, which doesn't support the use of attributes; but my custom header has to have attributes, for example :
Can't this be done, using the first three methods??
The fourth method works. The servicecontract is decorated with the XmlSerializerFormat which instructs WCF to use the XmlSerializer instead of the default DataContractSerializer. In the first three cases it seems WCF ignores the XmlSerializerFormat attribute on the servicecontract. Why is that?
I really dont want to add the MesageHeader explicitely in myMessageContract! I want it to be added dynamically like using a messageinspector or a custom channel.
Is this possible? Does anybody have experience creating custom (complex!) message headers? And adding these custom headers dynamically?