3

I have implemented message layer security using message inspector mechanism in a wcf service.

On the client side, in IClientMessageInspector.BeforeSendRequest I add an authentication header. On the service side, in IDispatchMessageInspector.AfterReceiveRequest I inspect the authentication header in the message. If it is not found or as expected, I throw a SecurityException and try to log it to a database. Here comes the interesting part. When logging to database, I try to read from this webservice again (this is web service which provides configuration info). This is where the service stalls/deadlocks. I can see that the call to read configuration (when logging to db) is made, but I don't receive the call on the service. I keep getting a timedout exception every time.

After a little googling, I came across this post, which mentions that message inspectors are synchronous in nature. If that is so, how can I achieve what I am after?

Vishal Shah
  • 3,774
  • 4
  • 23
  • 25
  • 1
    It might be that the channel to called service ("configuration info") is faulted. Try WCF tracing. Also see [this](https://stackoverflow.com/questions/3892527/wcf-how-to-diagnose-faulted-channels). – Christian.K May 08 '18 at 14:44
  • I've enabling WCF tracing. From there I can see that the second service call times out. And even from debugging, I can see that the second call is made, but never received. I'm almost certain this is because message inspectors execute synchronously, i.e. it can only service one request at a time. I changed the logic inside the my message inspector to make the second service call in a new thread and then everything started working as expected. – Vishal Shah May 09 '18 at 05:57
  • To handle concurrency, using a GUID might be helpful. – rjose May 18 '18 at 07:49

0 Answers0