You can use either of the following methods to expand the WCF: Custom behavior and custom binding. Behavior is used to control internal communication methods, and binding elements are used to create channels that control external communication methods. Specifically, the behavior on the WCF client is used to modify the operations of some components. These components are mainly responsible for serializing the sent data in the message and deserializing the response. On the WCF server, behavior is used to modify the Scheduler Component (dispatcher) function. (The above is the original story in wcf3.5 secrets)
The types of custom behaviors include Operation selector, parameter checker, message formatter, and message checker. The operation selector returns the operation for processing messages. The parameter Checker can modify the called parameters. The message formatter is responsible for deserializing received messages and serializing the messages to be sent; the message Checker can operate and modify a message when the message passes the endpoint.
Based on the above description, we can determine that to intercept a WCF message, we can extend it by customizing the behavior extended WCF, and select the type of behavior to be customized as needed.
The implementation of custom behaviors is divided into three steps:
1. Declaration (implement corresponding interfaces)
2. Attaching (actions can be appended to an operation (implementing ioperationbehavior) or an endpoint (implementing iendpointbehavior ))
3. Notify (use the code or configuration file to notify WCF)