use*_*280 4 wcf singleton web-services
我需要创建一个WCF服务,一次只允许一个客户端.应拒绝所有其他请求,客户端必须稍后再次重试.该服务大约需要一分钟才能完成请求.
我试过了:
[ServiceBehavior(IncludeExceptionDetailInFaults=true,
InstanceContextMode=InstanceContextMode.Single,
ConcurrencyMode=ConcurrencyMode.Single)]
Run Code Online (Sandbox Code Playgroud)
但是如果我在客户端多次请求服务(使用多个线程),我会在第3个请求上获得超时异常,但该服务确实会执行第3个请求处理!
您还可以查看"ServiceThrottling"行为,它允许您在服务器端指定要支持的并发实例,并发调用和并发会话数 - 将它们全部设置为1,您应该拥有自己的行为.
<behaviors>
<serviceBehaviors>
<behavior name="Throttled">
<serviceThrottling maxConcurrentCalls="1"
maxConcurrentSessions="1"
maxConcurrentInstances="1" />
</behavior>
</serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
渣
| 归档时间: |
|
| 查看次数: |
844 次 |
| 最近记录: |