2011-09-30 119 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以保存工作模式数据,因此它将显示给所有人连接客户端作为服务器的通知。 –