2009-10-05 92 views
0

我已經寫了一篇使用NetTcpBinding進行通信的應用程序並向客戶推出了該應用程序。WCF Net Tcp綁定服務器拒絕超過5個連接

我有一個服務器應用程序接受來自客戶端的訂閱請求,然後將數據推送到客戶端。

客戶端在服務器連接了5個客戶端的網站上看到一個問題,它拒絕了。

有沒有人見過這種行爲?有誰知道可能是什麼原因造成的?它適用於較少的用戶。

我試圖自己診斷此刻,但我是新來的WCF,所以我想知道是否有這種問題的一些常見的解決方案?

我碰到下面的堆棧跟蹤(Sanitzes刪除客戶端名稱和產品名稱):

2009-09-30 13:03:16,308 [1] ERROR [(null)] - Failed to subscribe to the VDN server, there was no server listening for connections at the configured URI 
System.ServiceModel.EndpointNotFoundException: Could not connect to net.tcp://server:4000/VDNService. The connection attempt lasted for a time span of 00:00:01.0312236. TCP error code 10061: No connection could be made because the target machine actively refused it 10.65.1.42:4000. ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 10.65.1.42:4000 
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 
    at System.Net.Sockets.Socket.Connect(EndPoint remoteEP) 
    at System.ServiceModel.Channels.SocketConnectionInitiator.Connect(Uri uri, TimeSpan timeout) 
    --- End of inner exception stack trace --- 

Server stack trace: 
    at System.ServiceModel.Channels.SocketConnectionInitiator.Connect(Uri uri, TimeSpan timeout) 
    at System.ServiceModel.Channels.BufferedConnectionInitiator.Connect(Uri uri, TimeSpan timeout) 
    at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout) 
    at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout) 
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout) 
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade) 
    at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at ClientLib.IServer.Subscribe(List`1 groups) 
    at ClientLib.Client.Subscribe(List`1 groupNames) 

回答

4

的幾個問題前面:

  • 在您的服務器端,什麼是你的配置看喜歡?
  • 服務器運行的是什麼操作系統? (一些操作系統版本/版本有限制)
  • 你如何在你的服務器上託管你的WCF服務? (IIS與自託管)

基本上可以調整使用ServiceThrottling行爲的併發連接數,你可以定義

  • 併發呼叫最大數量
  • 最大併發數會話(包括TCP/IP傳輸會話)
  • 服務類實例的最大數目

要配置,試試這個:

<serviceBehaviors> 
    <behavior name="throttledService"> 
     <serviceThrottling 
      maxConcurrentCalls="10" 
      maxConcurrentInstances="10" 
      maxConcurrentSessions="10"/> 
    </behavior> 

,當然還有,你的服務配置便要引用行爲的配置。

沒有一個默認爲5,但: - 但在你的情況下,我會嘗試將所有的設置調整到25或者什麼,只是看看是否有任何區別,然後調整到你的需要(和監控服務器的CPU和內存負載)

馬克

UPDATE:
可以肯定也爲此在代碼 - 這樣的事情(在服務器端,你實例您ServiceHost類! ,如果你自己主機):

using (ServiceHost host = new ServiceHost(typeof(MyWCFService))) 
{ 
    ServiceThrottlingBehavior stb = new ServiceThrottlingBehavior(); 
    stb.MaxConcurrentCalls = 25; 
    stb.MaxConcurrentInstances = 25; 
    stb.MaxConcurrentSessions = 25; 

    host.Description.Behaviors.Add(stb); 

    host.Open(); 

    ... 
} 
+0

這個應用程序沒有WCF配置文件,因爲我手動編寫了基於教程的WCF組件。 我會看看是否有可能在代碼中更改這些變量的方法。 – 2009-10-05 10:42:34

+0

該綁定具有我希望嘗試的MaxConnections屬性。謝謝你的幫助。 – 2009-10-05 10:58:34

+0

好,但你是自我託管(控制檯應用程序,NT服務)或託管在IIS? – 2009-10-05 11:49:50