How to run code for each service request?

I need to run code similar to an HTTP module every time a request enters the WCF service. Some code examples can be authentication, throttling, logging, etc. What is the best way to execute a module every time a query is executed?

Edit to clarify

We will do a couple of things. First of all, we need to authenticate all requests. Each request will require the user to submit a set of credentials, such as an API key. We need to verify the correctness of the key before allowing the request to pass.

As for throttling, we need to limit the number of requests a particular user can make. Let them say 100 per hour or something like that.

0
c # web-services wcf
source share
1 answer

There are several extension points in WCF that you can use for what you want. However, you may have to use different extension points for different purposes.

For example, for logging, you can use IDispatchMessageInspector or IParameterInspector . You can use IErrorHandler to handle errors.

Throttling is not what you usually use for extensions, as in many cases built-in settings may suffice .

As for authentication, it has its own set of extension points in security, and there are several options, so you might want to clarify (or post a new question) with specifics so that we can recommend the appropriate mechanism.

+2
source share

All Articles