2011-03-18 38 views
1

我有一個WPF應用程序(主機)也就是說,除其他事項外,自託管與多家ServiceHosts(如下圖所示的例子)WCF - 很多很多很多的第一次機會異常被拋出 - 然後崩潰應用

WCF
host= new ServiceHost(typeof(Data)); 
ServiceEndpoint endpoint = _HostData.AddServiceEndpoint(typeof(IData), _tcpBindingBO, _netTcpAddress + "data"); 


// add throttle behaviour 
ServiceThrottlingBehavior throttle = host.Description.Behaviors.Find<ServiceThrottlingBehavior>(); 
if (throttle == null) 
{ 
    throttle = new ServiceThrottlingBehavior(); 

    throttle.MaxConcurrentCalls = _SymphonyHostProp.MaxConcurrentCalls;  // 200;   // default 16  // 64 
    throttle.MaxConcurrentInstances = _SymphonyHostProp.MaxConcurrentInstances; // 1000;  // default 26  // 464 
    throttle.MaxConcurrentSessions = _SymphonyHostProp.MaxConcurrentCalls;  // default 10  // 400 

    host.Description.Behaviors.Add(throttle); 
} 

// open the host - bring it into life! 
host.Open(); 

我有使用連接到該主機NetTcpBinding的這樣

int MaxBuffer = 64;  // 64 Mb 
int bufferSize = MaxBuffer * 1024 * 1024; // 67108864    

// ----------------------------------------- 
// binding for normal clients (default) 
// ----------------------------------------- 
_tcpBinding = new NetTcpBinding(SecurityMode.None, true); 
_tcpBinding.MaxBufferPoolSize = bufferSize; // 64 Mb 
_tcpBinding.MaxBufferSize = bufferSize; 
_tcpBinding.MaxReceivedMessageSize = bufferSize; 
_tcpBinding.TransferMode = TransferMode.Buffered; 
_tcpBinding.ReaderQuotas.MaxArrayLength = bufferSize; 
_tcpBinding.ReaderQuotas.MaxBytesPerRead = bufferSize; 
_tcpBinding.ReaderQuotas.MaxStringContentLength = bufferSize; 
_tcpBinding.MaxConnections = 100; 
//_tcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 5); 
_tcpBinding.SendTimeout = MyHost.SendTimeout; 
_tcpBinding.ReliableSession.Enabled = true; 
//tcpBinding.ReliableSession.InactivityTimeout = new TimeSpan(7, 0, 0, 0); // 7 days 

「數據」暴露對象被這樣定義的客戶機:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, 
ConcurrencyMode = ConcurrencyMode.Multiple, 
UseSynchronizationContext = false)] 
public class Data : HBase, IData 

的問題是,在主機的正常運行和大約50個用戶連接都突然在IDE輸出窗口的正顯示出數百WCF相關的錯誤進來。

然後,如果我很幸運,它消失了在幾秒鐘之後,但在此期間,整個用戶界面和主機應用程序的所有內容都凍結了,WCF不再爲其他用戶提供服務。然後當它回來時,一切都很好,直到它再次出現錯誤。

這裏似乎沒有任何內部網絡問題。我已經啓用了跟蹤功能,但是我找不到有用的信息。 我只是想知道有沒有人經歷過這種行爲?

如果需要,我很樂意提供更多信息!

這些錯誤的1000個是在我的輸出窗口中創建的。

A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll 
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll 

回答

2

第一次機會異常不是錯誤。這些通常會被捕獲的例外。你應該忽略它們。

您應該擔心的異常是未捕獲的異常。

+0

我知道我可以不理會他們,但只要這些錯誤開始進來(在他們1000年)主機減慢,凍結UI,並最終有時會崩潰。任何人都可以照亮可能發生的事情嗎? – Marcel 2011-03-18 22:14:33

+0

什麼都沒有發生。你假設這些與你的問題有關。他們可能不會。你已經開始關注香腸是如何製作的,而且你不太喜歡它。 – 2011-03-18 22:49:01

+0

如果你認爲這些含義是什麼,那麼我建議你打開WCF跟蹤,看看你是否可以得到更多關於發生的事情的更多細節。另外,用Fiddler或其他東西來看網絡。 – 2011-03-18 22:49:59

1

我最近遇到這個問題。在我的情況下,我使用的是自定義log4net WCF Appender,log4net庫的設計目的是永遠不會拋出未捕獲的異常,這就是爲什麼我在調試窗口中獲得A first chance exception的原因。我只需要將我的客戶端調用和服務本身包裝在try catch塊中,這樣我就可以在log4net之前攔截異常,這使我能夠找到真正的原因。

儘管您的異常似乎源於不同的問題,但解決方案仍然是相同的。獲得這些嘗試/追趕,以便您可以獲得完整的錯誤細節並找出問題的根源。

順便說一句,如果您的整個應用程序崩潰,您可以使用一個非常方便的技巧來獲取未捕獲的異常,並將其崩潰。作爲應用程序啓動只需儘快調用此方法,

AppDomain.Current.UnhandledException += (sender, error) => File.AppendAllText("Fatal.log", error.ExceptionObject.ToString() + "\r\n");