获取当前默认的maxConcurrentSessions设置

本文关键字:maxConcurrentSessions 设置 默认 获取 | 更新日期: 2023-09-27 18:04:39

谁知道我如何通过代码获得基于WCF服务的会话上maxConcurrentSessions的当前设置?

我想得到这个值,即使maxConcurrentSessions没有在服务配置文件中设置,换句话说,我想在这种情况下得到默认值。

基本上,我试图证明没有任何疑问,在我当前的环境中,maxConcurrentSessions的默认值是什么。

谢谢!

获取当前默认的maxConcurrentSessions设置

技巧是在配置文件中设置一些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 * nb。

这篇文章可能会有所帮助…在底部有一节关于读取节流值。

你需要在服务器端完成它(例如在你的一个服务方法中)。此外,在示例中,它正在获取第一个ChannelDispatcher....对于您的特定场景,根据您正在做的事情,您可能有超过1个(不确定),因此这可能也是您需要考虑的条件。

HTH,内森

相关文章:
  • 没有找到相关文章