2011-09-30 33 views
8

我在客戶端服務器應用程序中使用WCF服務,並且在服務器和客戶端之間進行通信時遇到以下錯誤。WCF服務通道中的CommunicationObjectAbortedException,同時多個數據加載

Error Message =>> System.ServiceModel.CommunicationObjectAbortedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it has been Aborted. 

Server stack trace: 
    at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen() 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    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 ServiceLib.ServiceCallbackInterfaces.IHostServiceCallback.SendEventAndStatus(String message, Boolean isBackupGenerated) 
    at ServiceLib.Services.DriversService.objDriver_EventReceived(Object sender, EventReceivedEventArgs e) 

應用場景:客戶端通過WCF服務正從服務器的數據,並使用nettcp結合。服務器與真實設備連接,每秒生成20-30個事件。使用WCF的回調接口將生成的事件作爲字符串消息推送到所有連接的客戶端。如果客戶端沒有任何進程負載(只是接收事件和顯示),它工作正常。但是當我們在客戶端執行一些加載過程並且在一段時間內忙碌時,它會給出錯誤。

注意:我已經在nettcp綁定中設置了最大的所有超時如下,但仍然沒有解決問題。

NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None); 
       tcpBinding.MaxBufferPoolSize = 2147483647; 
       tcpBinding.MaxReceivedMessageSize = 2147483647; 
       tcpBinding.MaxBufferSize = 2147483647; 
       tcpBinding.ReaderQuotas.MaxStringContentLength = 2147483647; 
       tcpBinding.ReaderQuotas.MaxDepth = 2147483647; 
       tcpBinding.ReaderQuotas.MaxBytesPerRead = 2147483647; 
       tcpBinding.ReaderQuotas.MaxNameTableCharCount = 2147483647; 
       tcpBinding.ReaderQuotas.MaxArrayLength = 2147483647; 
       tcpBinding.SendTimeout = TimeSpan.MaxValue; 
       tcpBinding.ReceiveTimeout = TimeSpan.MaxValue; 
       tcpBinding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue; 

請指導我是否有任何其他需要與通信通道或綁定相關的設置?

UPDATE:錯誤的SVC示蹤拋出:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> 
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"> 
<EventID>131075</EventID> 
<Type>3</Type> 
<SubType Name="Error">0</SubType> 
<Level>2</Level> 
<TimeCreated SystemTime="2011-09-30T08:37:01.5691715Z" /> 
<Source Name="System.ServiceModel" /> 
<Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /> 
<Execution ProcessName="ServerUtility" ProcessID="2396" ThreadID="5" /> 
<Channel /> 
<Computer>TEST</Computer> 
</System> 
<ApplicationData> 
<TraceData> 
<DataItem> 
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"> 
<TraceIdentifier>http://msdn.microsoft.com/it-IT/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier> 
<Description>Throwing an exception.</Description> 
<AppDomain>ServerUtility.exe</AppDomain> 
<Exception> 
<ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> 
<Message>The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '10675199.02:48:05.4775807'.</Message> 
<StackTrace> 
at System.ServiceModel.Channels.SocketConnection.EndRead() 
at System.ServiceModel.Channels.DelegatingConnection.EndRead() 
at System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state) 
at System.ServiceModel.Channels.SocketConnection.FinishRead() 
at System.ServiceModel.Channels.SocketConnection.AsyncReadCallback(Boolean haveResult, Int32 error, Int32 bytesRead) 
at System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32 error, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) 
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 
</StackTrace> 
<ExceptionString>System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '10675199.02:48:05.4775807'. ---&gt; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host 
    --- End of inner exception stack trace ---</ExceptionString> 
<InnerException> 
<ExceptionType>System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> 
<Message>An existing connection was forcibly closed by the remote host</Message> 
<StackTrace> 
at System.ServiceModel.Channels.SocketConnection.EndRead() 
at System.ServiceModel.Channels.DelegatingConnection.EndRead() 
at System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state) 
at System.ServiceModel.Channels.SocketConnection.FinishRead() 
at System.ServiceModel.Channels.SocketConnection.AsyncReadCallback(Boolean haveResult, Int32 error, Int32 bytesRead) 
at System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32 error, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) 
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 
</StackTrace> 
<ExceptionString>System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host</ExceptionString> 
<NativeErrorCode>2746</NativeErrorCode> 
</InnerException> 
</Exception> 
</TraceRecord> 
</DataItem> 
</TraceData> 
<System.Diagnostics xmlns="http://schemas.microsoft.com/2004/08/System.Diagnostics"> 
<LogicalOperationStack></LogicalOperationStack> 
<Timestamp>4730654290080</Timestamp> 
</System.Diagnostics> 
</ApplicationData> 
</E2ETraceEvent> 
+0

檢查服務是否拋出任何異常 - 未處理的異常將對通道進行錯誤處理;它可能不是一個有約束力的問題。 – Tim

+1

@Tim說過的話;要使用服務跟蹤查看器,請訪問http://msdn.microsoft.com/en-us/library/ms732023.aspx –

+0

@JeremyMcGee:我對如何使用服務跟蹤查看器沒有多少了解。你能指導我嗎? –

回答

4

正如你在你的問題中提到,您已經將所有超時最大。所以根據我的觀點,在您定義的InstanceContextMode中應該存在問題。您在服務中定義了哪種模式? PerSession,PerCall或Single。可能存在PerCall,您可以通過同一對象(全局聲明的服務對象)定義和調用服務,那麼可能會導致進入故障狀態或斷開連接。

因此,如果您定義了PerSession模式,則使用客戶端的單個對象(全局聲明)從服務中獲取數據。如果您定義了PerCall選項,那麼每次都創建一個新對象。

希望對你有所幫助。請隨時詢問任何疑問...

+0

我有多個服務,一個名爲HostService的主服務具有PerSession模式,而其他所有服務都具有PerCall模式。在主要服務中,我維護靜態哈希表中連接的客戶端列表,因爲我需要使用回調方法將事件推送到所有客戶端。所以我將所有連接的客戶端的conext對象存儲在該列表中。在客戶端,我每次都需要新的對象來調用服務。 –

+0

您能否描述您如何向所有客戶發送事件通知?我的意思是你可以發佈一些代碼。還有一件事情是當你向客戶發送事件通知時,那麼你打電話給另一個有PerCall模式的服務? – Chief

+0

正如我前面告訴過你的,我使用回調方法發送事件通知,當我在客戶端應用程序中更改工作模式(主管,設置,離線)時,我正在調用EventLogService以保存工作模式數據,因此它將顯示給所有人連接客戶端作爲服務器的通知。 –