none
CommunicationObject由于发生异常出错,已中止“System.ServiceModel.Channels.HttpChannelFactory`1+HttpRequestChannel[System.ServiceModel.Channels.IRequestChannel]/66966689 RRS feed

  • 问题

  • 大家好,我在使用wcf时,出现了这个问题.

    服务端wcf我是这样设置的:

     WSHttpBinding httpBinding = new WSHttpBinding();
    
               httpBinding.ReceiveTimeout = TimeSpan.FromMinutes(5);
               httpBinding.SendTimeout = TimeSpan.FromMinutes(5);
               httpBinding.MaxBufferPoolSize = 900000000;
               httpBinding.MaxReceivedMessageSize = 900000000;
    
               httpBinding.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(5);
               httpBinding.ReliableSession.Enabled = true;
               httpBinding.ReliableSession.Ordered = true;
    
               httpBinding.Security.Mode = SecurityMode.None;
               httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

    然后client端这样设置的:

     <wsHttpBinding>
            <binding name="BasicHttpBinding" closeTimeout="00:01:00" openTimeout="00:30:00" receiveTimeout="00:05:00" sendTimeout="00:05:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"  useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
              <reliableSession ordered="true" inactivityTimeout="00:05:00"
                 enabled="true" />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                <message clientCredentialType="UserName" algorithmSuite="Default"/>
              </security>
            </binding>
          </wsHttpBinding>

    然后他就报这样的错了.请问怎么才能避免出现下面这个错误?谢谢

    <E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"> <EventID>524298</EventID> <Type>3</Type> <SubType Name="Information">0</SubType> <Level>8</Level> <TimeCreated SystemTime="2014-09-25T02:36:12.0964618Z" /> <Source Name="System.ServiceModel" /> <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /> <Execution ProcessName="w3wp" ProcessID="6500" ThreadID="23" /> <Channel /> <Computer>BRIAN-PC</Computer> </System> <ApplicationData> <TraceData> <DataItem> <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"> <TraceIdentifier>http://msdn.microsoft.com/zh-CN/library/System.ServiceModel.CommunicationObjectFaultReason.aspx</TraceIdentifier> <Description>CommunicationObject 由于发生异常而出错。</Description> <AppDomain>/LM/W3SVC/4/ROOT-1-130560857698504546</AppDomain> <ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTraceRecord"></ExtendedData> <Exception> <ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> <Message>远程终结点不再能识别此序列。这很可能是由于远程终结点上发生中止。WSRM:Identifier 的值不是已知的序列标识符。 可靠会话出错。</Message> <StackTrace> 在 System.ServiceModel.Channels.CommunicationObject.Fault(Exception exception) 在 System.ServiceModel.Channels.ChannelReliableSession.OnRemoteFault(Exception e) 在 System.ServiceModel.Channels.ChannelReliableSession.ProcessInfo(WsrmMessageInfo info, RequestContext context, Boolean throwException) 在 System.ServiceModel.Channels.ReliableRequestSessionChannel.ProcessReply(Message reply, IReliableRequest request, Int64 requestSequenceNumber) 在 System.ServiceModel.Channels.ReliableRequestSessionChannel.EndSendAckRequestedMessage(IAsyncResult result) 在 System.ServiceModel.Channels.ReliableRequestSessionChannel.OnPollingComplete(IAsyncResult result) 在 System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) 在 System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) 在 System.Runtime.AsyncResult.Complete(Boolean completedSynchronously, Exception exception) 在 System.ServiceModel.Channels.ReliableOutputAsyncResult.OperationCallback(IAsyncResult result) 在 System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) 在 System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) 在 System.Runtime.AsyncResult.Complete(Boolean completedSynchronously, Exception exception) 在 System.ServiceModel.Channels.ReliableChannelBinder`1.OutputAsyncResult`1.OnOutputComplete(IAsyncResult result) 在 System.ServiceModel.Channels.ReliableChannelBinder`1.OutputAsyncResult`1.OnOutputCompleteStatic(IAsyncResult result) 在 System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) 在 System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) 在 System.Runtime.AsyncResult.Complete(Boolean completedSynchronously, Exception exception) 在 System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result) 在 System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) 在 System.Net.LazyAsyncResult.Complete(IntPtr userToken) 在 System.Net.ContextAwareResult.CompleteCallback(Object state) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Net.ContextAwareResult.Complete(IntPtr userToken) 在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) 在 System.Net.HttpWebRequest.ProcessResponse() 在 System.Net.HttpWebRequest.SetResponse(CoreResponseData coreResponseData) 在 System.Net.HttpWebRequest.SetAndOrProcessResponse(Object responseOrException) 在 System.Net.ConnectionReturnResult.SetResponses(ConnectionReturnResult returnResult) 在 System.Net.Connection.ReadComplete(Int32 bytesRead, WebExceptionStatus errorStatus) 在 System.Net.Connection.ReadCallback(IAsyncResult asyncResult) 在 System.Net.Connection.ReadCallbackWrapper(IAsyncResult asyncResult) 在 System.Net.LazyAsyncResult.Complete(IntPtr userToken) 在 System.Net.ContextAwareResult.Complete(IntPtr userToken) 在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) 在 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) </StackTrace> <ExceptionString>System.ServiceModel.CommunicationException: 远程终结点不再能识别此序列。这很可能是由于远程终结点上发生中止。WSRM:Identifier 的值不是已知的序列标识符。 可靠会话出错。</ExceptionString> </Exception> </TraceRecord> </DataItem> </TraceData> </ApplicationData> </E2ETraceEvent>


    2014年9月25日 3:01

答案

  • 你好, 

    上面的异常一般由WCF服务器端的receiveTimeOut 或 InactivityTimeout 造成。当客户端和服务端没有交互特定时间

    服务器会断开连接, 而你的客户端会出现这个问题。 如你的配置:

    httpBinding.ReceiveTimeout = TimeSpan.FromMinutes(5);
    httpBinding.SendTimeout = TimeSpan.FromMinutes(5);
    ...........
    httpBinding.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(5);
    ..............
    

    客户端和服务端5分钟内没有交互,就会断开连接。 此类问题不可避免, 只有try-catch一下。

    你还可以选择延长连接时间 设置更长时间。

    谢谢


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    2014年9月26日 10:08
    版主