2

I'm not sure how simple this is but I am trying to achieve a WCF Restful Service but whenever a method is hit I want it "intercepted", This interception will check if header information exists identifying the user.

At the moment I am researching the best way to do this and have come across numerous mechanisms.

Search results before posting this comes up with "WCF REST Starter Kit" but my searching indicates this is abandoned!

Additionally, there is apparently something called a "RequestInterceptor" but not found a great deal on this either. I have come across the "ServiceAuthorizationManager" which I have had trouble with for a few days now (in the sense that it never gets called even though I set it the config)

<serviceAuthorization serviceAuthorizationManagerType="SomeNamespace.MyAuthorizationManager,SomeNamespace" />

I have my service operational and one way I have this validation working is via inheritance. Not a great approach but hoping for someone to suggest a better way.

No restriction on version of .NET as this is a personal exercise I am working on :)

Shahbaz
  • 46,337
  • 19
  • 116
  • 182
Dr Schizo
  • 4,045
  • 7
  • 38
  • 77
  • To be clear: Is the purpose of this interception to authenticate the caller (by checking your header) and then to grant or deny access based on the authenticated user identity? – Mike Goodwin Jul 26 '13 at 11:23
  • Absolutely correct. I want to perform some checking as on initial log on I am thinking of sending a response back with a check digit (something along these lines) and every method is expecting this in the header which will evaluate whether its been tampered with. Early stages yet but is what I am trying to achieve. – Dr Schizo Jul 26 '13 at 11:24
  • I think the correct approach for WCF is to use a combination of ServiceAuthenticationManager and ServiceAuthorizationManager as shown in this answer http://stackoverflow.com/questions/3715778/custom-wcf-authentication-with-system-servicemodel-serviceauthenticationmanager/3839743#3839743 – Mike Goodwin Jul 26 '13 at 11:26

1 Answers1

0

If you want to inspect incoming request Messages, check Message Inspectors

Dominik
  • 3,342
  • 1
  • 17
  • 24
  • I tried that but I imagine whenever I make a request my custom IDispatchMessageInspector should fire right? – Dr Schizo Jul 26 '13 at 12:01
  • If the Service you are calling is using the appropiate behavior, yes – Dominik Jul 26 '13 at 12:56
  • Maybe my config is wrong but I tried what you are saying and its not working for me. Tried this http://stackoverflow.com/a/7506438/1134076. – Dr Schizo Jul 26 '13 at 13:29
  • You sent me down the right path to enlightenment and lead me to this here http://stackoverflow.com/a/5266178/1134076. Solved the problem although need to decorate my services with a custom behavior. Not great but my god it works now after a week of pain! At least now making some progress. – Dr Schizo Jul 26 '13 at 13:48