我的WCF服务库作为Windows服务托管,应该处理来自多个客户端的请求.客户经常要做的一个请求是资源密集型.
我有两个与上述场景有关的疑问:
谢谢!
mar*_*c_s 11
在您的默认方案中,WCF服务主机(托管您的服务类的东西)将为每个进入的请求创建服务类的新实例,并允许它处理请求("每次调用"激活).
您可以使用serviceThrottling服务器上的行为调整这些并发活动服务类实例的最大数量.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ThrottledServiceBehavior">
<serviceThrottling
maxConcurrentCalls="25"
maxConcurrentSessions="25"
maxConcurrentInstances="25"/>
</behavior>
</serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
在Kenny Wolf的博客文章中,对服务限制行为的选项及其默认值有一个非常好的解释.
此外,设置InstanceContextMode和ConcurrencyMode服务类(实现服务合同)对服务如何处理并发和多个请求有很大影响.
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall,
ConcurrencyMode=ConcurrencyMode.Single)]
class YourServiceClass : IYourService
{
.....
}
Run Code Online (Sandbox Code Playgroud)
InstanceContextMode应该是PerCall(每个调用请求获得一个新的,单独的实例)然后ConcurrencyMode可以Single(这是最容易开发).
InstanceContextMode也可能PerSession是你需要一个基于会话的方法(不是很常见),或者Single(你的服务类会单身 - 非常不鼓励使用它,除非你绝对,积极地必须知道它的所有怪癖和问题! ).
ConcurrencyMode也可能Reentrant(仅与双工合同和绑定相关)或Multiple(多线程单件服务类 - 风险高且难以开发!).
渣
| 归档时间: |
|
| 查看次数: |
7649 次 |
| 最近记录: |