I am looking at implementing IDispatchMessageInpector & IClientMessageInpector to look at the message objects in AfterReceiveRequest and BeforeSendRequest Methods. My requirement is to make changes at code level of WCF service. No Configuration Changes. How to attach this behaviour to all the endpoints which are calling this service and to service itself. Is implementing IContractBehaviour helps me?
Edit 1: WCF Service is hosted on IIS. Is it possible to add the behavior thru code?
Edit 2: Seems like using ServiceHostFactory we can achieve this. How can i add behavior to client endpoint which are defined in webconfig?
Using ServiceHostFactory we can add service behavior whereas adding behavior configuration to client endpoints which are in config seems like not possible to achieve. So i am going with configuration changes
yes, it is possible to add behavior for services hosted in IIS. Behaviors are not concerned with the hosting environment of the service. Carlos Figueira's blog provides examples of all types of behaviors you could apply to Service, Endpoints, Contracts and Operations. A sample code that I tried for my service hosted in IIS (with endpoint defined in web.config file) - Config file here needs to add the behavior as ExtensionElement
Config file with behavior added as extension element -