2013-03-19 126 views
2

任何人都有一个想法,我怎么可以通过代码,基于会话的WCF服务maxConcurrentSessions的当前设置?获取当前默认maxConcurrentSessions设置

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

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

谢谢!

回答

3

关键是要设置在配置文件中的一些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处理器。

+0

只是为了直接设置记录:从[MSDN](http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentsessions.aspx)它说,从.NET 4.5:“默认值是处理器数量的100倍。“而对于.NET 4.0 [MSDN](http://msdn.microsoft.com/zh-cn/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentsessions(v = vs.100).aspx)指出:“缺省值是10.” :) – 2013-10-14 13:10:31

1

this文章可能有帮助...在底部有一节阅读节流值。

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

HTH,弥敦道

+0

THANKs,这是接近解决方案,我敢肯定,但我没有得到throttleBehavior如果没有在配置文件中设置...发现一个把戏现在会发布它。 – zukanta 2013-03-19 19:57:03