4

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

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

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

谢谢!

4

2 回答 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 * nb。

于 2013-03-19T20:31:10.877 回答
1

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

您需要在服务器端进行(例如,在您的一种服务方法中)。此外,在示例中,它获得了第一个 ChannelDispatcher....对于您的特定场景,您可能有超过 1 个(不确定),具体取决于您正在做什么,这可能是您还需要考虑的一个条件。

HTH,弥敦道

于 2013-03-19T19:06:07.507 回答