Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF:奇怪的通信对象AbortedException_C#_Wcf - Fatal编程技术网

C# WCF:奇怪的通信对象AbortedException

C# WCF:奇怪的通信对象AbortedException,c#,wcf,C#,Wcf,在WCF中,我认为我可以处理所有的情况,在这些情况下,客户端可以通过订阅关闭和故障事件(如下所示)而出现故障 private ConcurrentDictionary<string,ICallback> dict=new ConcurrentDictionary<string,ICallback>(); public void Initialize(IClientChannel channel) { channel.Closed += new

在WCF中,我认为我可以处理所有的情况,在这些情况下,客户端可以通过订阅关闭和故障事件(如下所示)而出现故障

private ConcurrentDictionary<string,ICallback> dict=new ConcurrentDictionary<string,ICallback>();

public void Initialize(IClientChannel channel)
    {

        channel.Closed += new EventHandler(disconnected);
        channel.Faulted += new EventHandler(disconnected);
    }

   private void disconnected(object sender, EventArgs e)
   {
    //Remove from dict
   }
wcf服务的堆栈跟踪如下所示

<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="2015-04-23T08:46:52.6535251Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{1d3c72e6-a5bb-46bf-b09f-8352e7ed7cfe}" /><Execution ProcessName="MyServiceHosting" ProcessID="2232" ThreadID="4" /><Channel /><Computer>SERVER</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier><Description>Throwing an exception.</Description><AppDomain>KaraokeServiceHosting.exe</AppDomain><Source>System.ServiceModel.Channels.ServerReliableDuplexSessionChannel/59817589</Source><Exception><ExceptionType>System.ServiceModel.CommunicationObjectAbortedException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>The communication object, System.ServiceModel.Channels.ServerReliableDuplexSessionChannel, cannot be used for communication because it has been Aborted.</Message><StackTrace>   at System.ServiceModel.Channels.CommunicationObject.ThrowIfAborted()
   at System.ServiceModel.Channels.InputQueueChannel`1.EndDequeue(IAsyncResult result, TDisposable&amp;amp; item)
   at System.ServiceModel.Channels.DuplexChannel.EndTryReceive(IAsyncResult result, Message&amp;amp; message)
   at System.ServiceModel.Dispatcher.DuplexChannelBinder.EndTryReceive(IAsyncResult result, RequestContext&amp;amp; requestContext)
   at System.ServiceModel.Dispatcher.ErrorHandlingReceiver.EndTryReceive(IAsyncResult result, RequestContext&amp;amp; requestContext)
   at System.ServiceModel.Dispatcher.ChannelHandler.EndTryReceive(IAsyncResult result, RequestContext&amp;amp; requestContext)
   at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
   at System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
   at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
   at System.ServiceModel.Diagnostics.TraceUtility.&amp;lt;&amp;gt;c__DisplayClass4.&amp;lt;CallbackGenerator&amp;gt;b__2(AsyncCallback callback, IAsyncResult result)
   at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
   at System.Runtime.InputQueue`1.AsyncQueueReader.Set(Item item)
   at System.Runtime.InputQueue`1.Shutdown(Func`1 pendingExceptionGenerator)
   at System.ServiceModel.Channels.InputQueueChannel`1.OnClosing()
   at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnClosing()
   at System.ServiceModel.Channels.CommunicationObject.Abort()
   at System.ServiceModel.Dispatcher.DuplexChannelBinder.Abort()
   at System.ServiceModel.Channels.ServiceChannel.OnAbort()
   at System.ServiceModel.Channels.CommunicationObject.Abort()
   at System.ServiceModel.Channels.ServiceChannel.OnInnerChannelFaulted(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.ServiceModel.Channels.CommunicationObject.OnFaulted()
   at System.ServiceModel.Channels.InputQueueChannel`1.OnFaulted()
   at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnFaulted()
   at System.ServiceModel.Channels.ServerReliableDuplexSessionChannel.OnFaulted()
   at System.ServiceModel.Channels.CommunicationObject.Fault()
   at System.ServiceModel.Channels.CommunicationObject.Fault(Exception exception)
   at System.ServiceModel.Channels.ChannelReliableSession.OnLocalFault(Exception e, Message faultMessage, RequestContext context)
   at System.ServiceModel.Channels.ChannelReliableSession.OnLocalFault(Exception e, WsrmFault fault, RequestContext context)
   at System.ServiceModel.Channels.ChannelReliableSession.OnInactivityElapsed(Object state)
   at System.ServiceModel.Channels.InterruptibleTimer.OnTimerElapsed()
   at System.ServiceModel.Channels.InterruptibleTimer.OnTimerElapsed(Object state)
   at System.Runtime.ActionItem.DefaultActionItem.TraceAndInvoke()
   at System.Runtime.ActionItem.DefaultActionItem.Invoke()
   at System.Runtime.ActionItem.CallbackHelper.InvokeWithoutContext(Object state)
   at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, 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.CommunicationObjectAbortedException: The communication object, System.ServiceModel.Channels.ServerReliableDuplexSessionChannel, cannot be used for communication because it has been Aborted.</ExceptionString></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent>
131075302服务器和


但是它们只解释了如何检测我已经实现的死客户端案例。

您的IsChannelValid方法没有遵循正确的方法。你可以通过这样做来结束比赛

检查ICommunicationObject.State属性的值是竞争条件,不建议用于确定是否重用或关闭通道

<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="2015-04-23T08:46:52.6535251Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{1d3c72e6-a5bb-46bf-b09f-8352e7ed7cfe}" /><Execution ProcessName="MyServiceHosting" ProcessID="2232" ThreadID="4" /><Channel /><Computer>SERVER</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier><Description>Throwing an exception.</Description><AppDomain>KaraokeServiceHosting.exe</AppDomain><Source>System.ServiceModel.Channels.ServerReliableDuplexSessionChannel/59817589</Source><Exception><ExceptionType>System.ServiceModel.CommunicationObjectAbortedException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>The communication object, System.ServiceModel.Channels.ServerReliableDuplexSessionChannel, cannot be used for communication because it has been Aborted.</Message><StackTrace>   at System.ServiceModel.Channels.CommunicationObject.ThrowIfAborted()
   at System.ServiceModel.Channels.InputQueueChannel`1.EndDequeue(IAsyncResult result, TDisposable&amp;amp; item)
   at System.ServiceModel.Channels.DuplexChannel.EndTryReceive(IAsyncResult result, Message&amp;amp; message)
   at System.ServiceModel.Dispatcher.DuplexChannelBinder.EndTryReceive(IAsyncResult result, RequestContext&amp;amp; requestContext)
   at System.ServiceModel.Dispatcher.ErrorHandlingReceiver.EndTryReceive(IAsyncResult result, RequestContext&amp;amp; requestContext)
   at System.ServiceModel.Dispatcher.ChannelHandler.EndTryReceive(IAsyncResult result, RequestContext&amp;amp; requestContext)
   at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
   at System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
   at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
   at System.ServiceModel.Diagnostics.TraceUtility.&amp;lt;&amp;gt;c__DisplayClass4.&amp;lt;CallbackGenerator&amp;gt;b__2(AsyncCallback callback, IAsyncResult result)
   at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
   at System.Runtime.InputQueue`1.AsyncQueueReader.Set(Item item)
   at System.Runtime.InputQueue`1.Shutdown(Func`1 pendingExceptionGenerator)
   at System.ServiceModel.Channels.InputQueueChannel`1.OnClosing()
   at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnClosing()
   at System.ServiceModel.Channels.CommunicationObject.Abort()
   at System.ServiceModel.Dispatcher.DuplexChannelBinder.Abort()
   at System.ServiceModel.Channels.ServiceChannel.OnAbort()
   at System.ServiceModel.Channels.CommunicationObject.Abort()
   at System.ServiceModel.Channels.ServiceChannel.OnInnerChannelFaulted(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.ServiceModel.Channels.CommunicationObject.OnFaulted()
   at System.ServiceModel.Channels.InputQueueChannel`1.OnFaulted()
   at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnFaulted()
   at System.ServiceModel.Channels.ServerReliableDuplexSessionChannel.OnFaulted()
   at System.ServiceModel.Channels.CommunicationObject.Fault()
   at System.ServiceModel.Channels.CommunicationObject.Fault(Exception exception)
   at System.ServiceModel.Channels.ChannelReliableSession.OnLocalFault(Exception e, Message faultMessage, RequestContext context)
   at System.ServiceModel.Channels.ChannelReliableSession.OnLocalFault(Exception e, WsrmFault fault, RequestContext context)
   at System.ServiceModel.Channels.ChannelReliableSession.OnInactivityElapsed(Object state)
   at System.ServiceModel.Channels.InterruptibleTimer.OnTimerElapsed()
   at System.ServiceModel.Channels.InterruptibleTimer.OnTimerElapsed(Object state)
   at System.Runtime.ActionItem.DefaultActionItem.TraceAndInvoke()
   at System.Runtime.ActionItem.DefaultActionItem.Invoke()
   at System.Runtime.ActionItem.CallbackHelper.InvokeWithoutContext(Object state)
   at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, 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.CommunicationObjectAbortedException: The communication object, System.ServiceModel.Channels.ServerReliableDuplexSessionChannel, cannot be used for communication because it has been Aborted.</ExceptionString></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent>