2013-03-19 124 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