请问有没有人知道如何通过代码获取基于会话的WCF服务的maxConcurrentSessions当前设置?
我希望即使在服务配置文件中没有设置maxConcurrentSessions,也能获取此值,换句话说,我想在这种情况下获得默认值。
基本上,我正在尝试毫无疑问地证明,我的当前环境中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倍。
this这篇文章可能会有所帮助......在底部有一个关于读取被限制值的部分。
您需要在服务器端执行此操作(例如,在您的服务方法之一内部)。此外,在示例中,它正在获取第一个ChannelDispatcher....对于您特定的情况,您可能有多个(不确定),具体取决于您正在做什么,因此这也可能是您需要考虑的条件。
希望对您有所帮助,Nathan