获取当前默认的maxConcurrentSessions设置

4

请问有没有人知道如何通过代码获取基于会话的WCF服务的maxConcurrentSessions当前设置?

我希望即使在服务配置文件中没有设置maxConcurrentSessions,也能获取此值,换句话说,我想在这种情况下获得默认值。

基本上,我正在尝试毫无疑问地证明,我的当前环境中maxConcurrentSessions的默认值是什么。

谢谢!

2个回答

4
关键是在配置文件中设置一些throttlingBehavior属性,但是保留maxConcurrentSessions。
 <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100"/>

然后在服务器上:

ServiceHost host = new ServiceHost(typeof(MyService));

string msg = "Service Behaviors:" + Environment.NewLine;
foreach (IServiceBehavior behavior in host.Description.Behaviors)
{
    msg += behavior.ToString() + Environment.NewLine;

    if (behavior is ServiceThrottlingBehavior)
    {
        ServiceThrottlingBehavior serviceThrottlingBehavior = (ServiceThrottlingBehavior)behavior;
        msg += "     maxConcurrentSessions =   " + serviceThrottlingBehavior.MaxConcurrentSessions.ToString() + Environment.NewLine;
    }
}
EventLog.WriteEntry("My Log Source", msg,  EventLogEntryType.Information);

这对我来说是800。这证实了文档中所说的WCF 4.0及以上版本默认为处理器数量的100倍。


为了澄清事实:根据MSDN的说法,从.NET 4.5开始:“默认值是处理器数的100倍。”而对于.NET 4.0,MSDN则说明:“默认值为10。” :) - Lasse Christiansen

1

this这篇文章可能会有所帮助......在底部有一个关于读取被限制值的部分。

您需要在服务器端执行此操作(例如,在您的服务方法之一内部)。此外,在示例中,它正在获取第一个ChannelDispatcher....对于您特定的情况,您可能有多个(不确定),具体取决于您正在做什么,因此这也可能是您需要考虑的条件。

希望对您有所帮助,Nathan


谢谢,这很接近我确定的解决方案,但是如果配置文件中没有设置throttleBehavior,我将得不到它...找到了一个技巧,现在会发布它。 - zukanta

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接