开发者

How to run code on every service request?

I need to run some code similar to an HTTP module every time a request comes into a WCF service. Some examples of the code might be authentication, throttling, logging, etc. What is the best way to go about executing a module each time a request is made?

Edit For Clarification

We'll be doing a couple of things. First of all, we need to authenticate all requests. Each request will require the user to pass some set of credentials, say an API key. We need validate the key is correct before allowing the request to go through.

As for throttling, we'll need limit the number of requests a sp开发者_JAVA技巧ecific user can make. Let's say 100 per hour or something similar.


There are several extension points in WCF that can be used for what you want. You will likely need to use different extension points for different purposes, though.

For example, for logging you could use IDispatchMessageInspector or IParameterInspector. For Error handling you could use IErrorHandler.

Throttling is not something you typically use extensions for, as in many cases the built-in throttling settings might be enough.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜