How to throttle WCF service per client

前端 未结 3 2008
傲寒
傲寒 2020-12-19 22:51

I\'m developing a service that will be exposed on the internet to only a few select clients. However I don\'t want one client to be able to call the service so often that th

3条回答
  •  被撕碎了的回忆
    2020-12-19 23:32

    You could alter your configuration like this:

     ConcurrencyMode:=ConcurrencyMode.Single
     InstanceContextMode:=InstanceContextMode.Single
    

    Then, in code, set up two service-level variables:

    • one string variable to hold the ID of the last requestor
    • one integer variable for the number of visits.

    With each request where the ID of the inbound user == to last saved user, increment +1 your integer variable. After request 10, return a denial to the user. If the user's different, reset the variables and process the request.

    It's not a configuration solution - it's configuration and code, but it would work.

提交回复
热议问题