When designing a WCF
ServiceContract, we can add custom SoapHeaders into the WCF service operation through the
ServiceContract member statically. In addition to this, we can also programmatically create a custom SoapHeader and add it into a WCF request dynamically.
The first thing to do here is to generate an instance of the SoapHeader we want to add into the request message. WCF provides a built-in generic type called
MessageHeader<T> for creating custom SoapHeaders containing different kinds of inner data properties. The following code snippet shows how we can generate a custom SoapHeader that contains some string data through the
MessageHeader<T> type: ...