WCF: Service that only allows a single client and rejects others

為{幸葍}努か 提交于 2019-12-10 08:59:09

问题


I need to create a WCF service that only allows a single client at a time. All other requests should be rejected, and the client must retry again later. The service will take around a minute to complete the request.

I've tried:

 [ServiceBehavior(IncludeExceptionDetailInFaults=true,
                  InstanceContextMode=InstanceContextMode.Single,
                  ConcurrencyMode=ConcurrencyMode.Single)]

but if I request the service multiple times (using multiple threads) in a client, I get a timeout exception on the 3rd request, but the service does actually perform the 3rd requests processing!


回答1:


You could also check out the "ServiceThrottling" behavior, which allows you to specify on the server side how many concurrent instances, concurrent calls and concurrent sessions you want to support - set them all to 1, and you should have your behavior.

<behaviors>
  <serviceBehaviors>
     <behavior name="Throttled">
         <serviceThrottling maxConcurrentCalls="1"
            maxConcurrentSessions="1"
            maxConcurrentInstances="1" />
     </behavior>
  </serviceBehaviors>
</behaviors>

Marc



来源:https://stackoverflow.com/questions/799307/wcf-service-that-only-allows-a-single-client-and-rejects-others

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!