Building a custom MessageEncoder
MessageInspector can intercept the underlying messages of WCF service operation calls. However, this is not the only way for intercepting and customizing messages in a WCF service. In WCF extension architecture, there is another powerful component called MessageEncoder
, which can also perform customization on the underlying messages of WCF service operation calls.
In this recipe, we will demonstrate how we can use a custom MessageEncoder to alter the raw message of a WCF service operation.
How to do it...
The sample service will use a custom MessageEncoder
component to customize the SOAP XML content of each service operation call. The entire process will be as follows:
Create a custom
MessageEncoder
typeCreate a custom
MessageEncoderFactory
typeCreate a custom
EncoderBindingElement
type for registering the encoder in theBindingElement
stackInject the custom
EncoderBindingElement
into the target service endpoint
Let's look at each of these steps in detail.
Create...