I an developing a WCF service where I need to intercept incoming messages for custom validations. After my research, I found that I need to implement IDispatchMessageInspector for this purpose. So, I inserted my custom validations inside AfterReceiveRequest method of the interface.

The problem: When I debug the code, I saw that message reception do not trigger the AfterReceiveRequest method that I have implemented.

The question: Do I need to register my class/method somewhere to trigger when messages are received?

Was it helpful?


You have implemented the IDispatchMessageInspector - but have you added it to the ServiceHost's .Behaviors collection on the server side so that it will be included?

See this blog post for details - first you need to create a class implementing IEndpointBehavior (or a IServiceBehavior - whichever you need) and implement the ApplyDispatchBehavior method on it.

Then you need to either add this behavior to the ServiceHost before you open it, or you need to create another class to allow you to configure this behavior for your service.


Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow