C# 多数据加载时WCF服务通道中的CommunicationObjectAbortedException

C# 多数据加载时WCF服务通道中的CommunicationObjectAbortedException,c#,wcf,nettcpbinding,C#,Wcf,Nettcpbinding,我在我的客户机-服务器应用程序中使用WCF服务,在服务器和客户机之间通信时遇到以下错误 Error Message =>> System.ServiceModel.CommunicationObjectAbortedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it has been A

我在我的客户机-服务器应用程序中使用WCF服务,在服务器和客户机之间通信时遇到以下错误

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;
请告诉我是否需要其他与通信通道或绑定相关的设置

更新: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>

131075
3.
0
2.
试验
http://msdn.microsoft.com/it-IT/library/System.ServiceModel.Diagnostics.ThrowingException.aspx
正在引发异常。
ServerUtility.exe
System.ServiceModel.CommunicationException,System.ServiceModel,版本=4.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089
套接字连接已中止。这可能是由于处理消息时出错、远程主机超过接收超时或基础网络资源问题造成的。本地套接字超时为“10675199.02:48:05.4775807”。
位于System.ServiceModel.Channels.SocketConnection.EndRead()处
在System.ServiceModel.Channels.DelegatingConnection.EndRead()处
位于System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(对象状态)
在System.ServiceModel.Channels.SocketConnection.FinishRead()中
位于System.ServiceModel.Channel.SocketConnection.AsyncReadCallback(布尔haveResult、Int32错误、Int32字节读取)
在System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32错误,UInt32个字节,NativeOverlapped*NativeOverlapped)
在System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32错误,UInt32字节读取,NativeOverlapped*NativeOverlapped)
在System.Threading.\u IOCompletionCallback.PerformiCompletionCallback(UInt32错误代码,UInt32个字节,本机重叠*pOVERLAP)
System.ServiceModel.CommunicationException:套接字连接已中止。这可能是由于处理消息时出错、远程主机超过接收超时或基础网络资源问题造成的。本地套接字超时为'10675199.02:48:05.4775807'System.Net.Sockets.SocketException:远程主机强制关闭了现有连接
---内部异常堆栈跟踪的结束---
System.Net.Sockets.SocketException,系统,版本=4.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089
远程主机已强制关闭现有连接
位于System.ServiceModel.Channels.SocketConnection.EndRead()处
在System.ServiceModel.Channels.DelegatingConnection.EndRead()处
位于System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(对象状态)
在System.ServiceModel.Channels.SocketConnection.FinishRead()中
位于System.ServiceModel.Channel.SocketConnection.AsyncReadCallback(布尔haveResult、Int32错误、Int32字节读取)
在System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32错误,UInt32个字节,NativeOverlapped*NativeOverlapped)
在System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32错误,UInt32字节读取,NativeOverlapped*NativeOverlapped)
在System.Threading.\u IOCompletionCallback.PerformiCompletionCallback(UInt32错误代码,UInt32个字节,本机重叠*pOVERLAP)
System.Net.Sockets.SocketException(0x80004005):远程主机强制关闭了现有连接
2746
4730654290080

正如您在问题中提到的,您已将所有超时设置为最大值。所以根据我的观点,您定义的InstanceContextMode中应该存在问题。您在服务中定义了哪种模式?PerSession,PerCall或Single。可能存在由同一对象(全局声明的服务对象)定义和调用服务的PerCall,然后有可能通道处于故障状态或连接断开

所以,若您定义了PerSession模式,那个么从客户端使用单个对象(全局声明)从服务获取数据。如果定义了PerCall选项,则每次都要创建新对象


希望这对你有帮助。请随时询问任何疑问…

检查服务是否抛出任何异常-未处理的异常将导致频道故障;这可能不是一个有约束力的问题;要做到这一点,请使用服务跟踪查看器@JeremyMcGee:我不太清楚如何使用服务跟踪查看器。你能指导我吗?@UpendraChaudhari-查看杰里米发布的链接。确实如此。实际上,您需要调整配置以创建跟踪文件,然后使用跟踪查看器进行查看。我建议跟踪客户机/和/或服务器。还值得记住的是,您也可以跟踪序列化问题:我有多个服务,一个名为HostService的主服务具有PerSession模式,所有其他服务都具有PerCall模式。在主服务中,我在静态哈希表中维护连接的客户端列表,因为我需要使用回调方法将事件推送到所有客户端。因此,我将所有连接的客户端的conext对象存储在该列表中。在客户端,我每次都要创建一个新的对象来调用服务。您能描述一下如何向所有客户端发送事件通知吗?我的意思是你能帮我发一些代码吗。还有一件事是,当您向客户端发送事件通知时,您会调用另一个具有PerCall模式的服务?正如我之前告诉您的,我使用回调方法发送事件通知,当我在客户端应用程序中更改工作模式(主管、设置、脱机)时,我会调用EventLogService以保存工作模式数据,所以它会显示出来