views:

232

answers:

4

I have a RESTful WCF service with many different functions. For each function I need to call an authentication method that I have written. I can manually call this method on every request but I was looking for a way to force the WCF engine to call this method before these functions are entered. Does anyone know if this is possible?

Cheers

A: 

You could think about creating a WCF routing service. You would call a fixed endpoint - your authentication method - and then from there on, route your calls to the actual methods, based on some indication in the request.

Check out this two part series on writing a routing service in WCF 3.5 on MSDN Magazine:

For .NET 4, the Routing Service functionality will be included into WCF out of the box.

What I don't know is how that all matches REST, though.

marc_s
A: 

Almost Everything in WCF is customizable. Take a look on the web for custom Authentication and you will find a variety of blogs on howto use your own authenticator classes.

here is one.

rerun
+2  A: 

You could use the "Custom Behavior" approach.

You would need to write a Class with implements IDispatchMessageInspector. The following MSDN magazine article gives a nice explanation of this: Extending WCF with Custom Behaviors

Subbu
Isn't this overkill?
mafutrct
A: 

If it's for authorization, can't you use the built in services?

For instance, there is the PrincipalPermission attribute. Does that help in your case?

mafutrct