none
wcf使用nettcp绑定,服务器端trace日志如何分析原因? RRS feed

  • 问题

  • 服务配置如下:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <!--跟踪节点配置-->
      <runtime>
        <legacyUnhandledExceptionPolicy enabled="1" />
      </runtime>
      <system.serviceModel>
        <serviceHostingEnvironment minFreeMemoryPercentageToActivateService="5" />
        <client />
        <services>
          <service behaviorConfiguration="sb" name="MesWcfService.MesService">
            <endpoint address="net" binding="netTcpBinding"
              bindingConfiguration="bd" contract="MesWcfService.IMesService" />
            <endpoint address="net.tcp://localhost:8988/mex" binding="mexTcpBinding"
              contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:8989/" />
              </baseAddresses>
              <timeouts closeTimeout="00:01:00" openTimeout="00:01:00" />
            </host>
          </service>
        </services>
        <bindings>
          <netTcpBinding>
            <binding name="bd" closeTimeout="00:01:00" openTimeout="00:01:00"
              receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
              transferMode="Buffered" transactionProtocol="OleTransactions"
              hostNameComparisonMode="StrongWildcard" listenBacklog="1000"
              maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="1000"
              maxReceivedMessageSize="2147483647" portSharingEnabled="false">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="true" />
              <security mode="None">
                <transport clientCredentialType="None" protectionLevel="None" />
                <message clientCredentialType="None" />
              </security>
            </binding>
          </netTcpBinding>
        </bindings>
         <behaviors>
          <serviceBehaviors>
            <behavior name="sb">
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
              <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
              <serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="1000" maxConcurrentInstances="1000"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel></system.web></configuration>

    诊断日志信息:

    <ExceptionType>System.ServiceModel.CommunicationObjectAbortedException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
    <Message>无法将通信对象 System.ServiceModel.Channels.ServerReliableDuplexSessionChannel 用于通信,因为它已经被中止。</Message>
    <StackTrace>
    在 System.ServiceModel.Channels.CommunicationObject.ThrowIfAborted()
    在 System.ServiceModel.Channels.InputQueueChannel`1.EndDequeue(IAsyncResult result, TDisposable&amp; item)
    在 System.ServiceModel.Channels.DuplexChannel.EndTryReceive(IAsyncResult result, Message&amp; message)
    在 System.ServiceModel.Dispatcher.DuplexChannelBinder.EndTryReceive(IAsyncResult result, RequestContext&amp; requestContext)
    在 System.ServiceModel.Dispatcher.ErrorHandlingReceiver.EndTryReceive(IAsyncResult result, RequestContext&amp; requestContext)
    在 System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
    在 System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
    在 System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
    在 System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
    在 System.ServiceModel.Channels.InputQueue`1.AsyncQueueReader.Set(Item item)
    在 System.ServiceModel.Channels.InputQueue`1.Shutdown(CommunicationObject communicationObject)
    在 System.ServiceModel.Channels.InputQueueChannel`1.OnClosing()
    在 System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnClosing()
    在 System.ServiceModel.Channels.CommunicationObject.Abort()
    在 System.ServiceModel.Dispatcher.DuplexChannelBinder.Abort()
    在 System.ServiceModel.Channels.ServiceChannel.OnAbort()
    在 System.ServiceModel.Channels.CommunicationObject.Abort()
    在 System.ServiceModel.Channels.ServiceChannel.SessionIdleManager.TimerCallback()
    在 System.ServiceModel.Channels.ServiceChannel.SessionIdleManager.TimerCallback(Object state)
    在 System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2()
    在 System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.OnSecurityContextCallback(Object o)
    在 System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
    在 System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke()
    在 System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks()
    在 System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state)
    在 System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
    在 System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
    在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
    </StackTrace>
    <ExceptionString>System.ServiceModel.CommunicationObjectAbortedException: 无法将通信对象 System.ServiceModel.Channels.ServerReliableDuplexSessionChannel 用于通信,因为它已经被中止。</ExceptionString>

    <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="2016-01-13T05:21:28.7660207Z" />
    <Source Name="System.ServiceModel" />
    <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
    <Execution ProcessName="MESWCFHOST" ProcessID="724" ThreadID="53" />
    <Channel />
    <Computer>JYMESWCF01</Computer>
    </System>
    <ApplicationData>
    <TraceData>
    <DataItem>
    <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
    <TraceIdentifier>http://msdn.microsoft.com/zh-CN/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
    <Description>正在引发异常。</Description>
    <AppDomain>MESWCFHOST.exe</AppDomain>
    <Exception>
    <ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
    <Message>套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“10675199.02:48:05.4775807”。</Message>
    <StackTrace>
    在 System.ServiceModel.Channels.SocketConnection.EndRead()
    在 System.ServiceModel.Channels.DelegatingConnection.EndRead()
    在 System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)
    </StackTrace>
    <ExceptionString>System.ServiceModel.CommunicationException: 套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“10675199.02:48:05.4775807”。 ---&gt; System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接。
       --- 内部异常堆栈跟踪的结尾 ---
       在 System.ServiceModel.Channels.SocketConnection.EndRead()
       在 System.ServiceModel.Channels.DelegatingConnection.EndRead()
       在 System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)</ExceptionString>
    <InnerException>
    <ExceptionType>System.Net.Sockets.SocketException, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
    <Message>远程主机强迫关闭了一个现有的连接。</Message>
    <StackTrace>
    在 System.ServiceModel.Channels.SessionConnectionReader.GetPendingMessage()
    在 System.ServiceModel.Channels.SessionConnectionReader.EndReceive()
    在 System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.OnReceiveComplete(Object state)
    在 System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)
    在 System.ServiceModel.Channels.SocketConnection.FinishRead()
    在 System.ServiceModel.Channels.SocketConnection.AsyncReadCallback(Boolean haveResult, Int32 error, Int32 bytesRead)
    在 System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32 error, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
    在 System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
    在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
    </StackTrace>
    <ExceptionString>System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接。</ExceptionString>
    <NativeErrorCode>2746</NativeErrorCode>
    </InnerException>
    </Exception>
    </TraceRecord>
    </DataItem>
    </TraceData>
    </ApplicationData>
    </E2ETraceEvent>

    搞不懂问题出在哪里,客户端连接用完都马上关闭,不应该这么频繁的出现这个问题,难道就是因为用了可靠的会话?还是wcf对nettcp绑定支持不好?


    2016年1月8日 8:59

全部回复

  • 您好,

    请问您用的是那种可靠的会话方式,如果说是percall的话,当我们调用完服务就需要关闭代理。

    如果是per Session 的话,对于每个客户端来说,需要在结束的时候关闭通道。如果说,采用的是

    双工,那么当客户端关闭后,服务端还继续向客户端发送请求,那么就会报出异常。

    一般而言,导致这种错误的应该是验证失败或者是超时。

    感谢您的支持。


    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. Click HERE to participate the survey.

    2016年1月13日 2:04
    版主
  • 服务使用的是 这个配置

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]

      <reliableSession ordered="true" inactivityTimeout="00:10:00"    enabled="true" /> 使用的nettcp绑定,使用了可靠会话,经过这几天的测试,只要是nettcp绑定不管是否开启可靠会话都会trace出很多异常关闭的如上,使用http绑定的就再也trace不出来了。

    虽然可以trace异常服务正常使用,但是部署到服务器上后不定时出现服务不可用内存溢出的问题,日志如下:

    详细错误信息:基础连接已经关闭: 服务器关闭了本应保持活动状态的连接。
    2016-01-11 12:28:32.387: System.OutOfMemoryException: 引发类型为“System.OutOfMemoryException”的异常。
       在 System.ServiceModel.Channels.ReliableChannelListener`3.ProcessCreateSequence(WsrmMessageInfo info, TInnerChannel channel, Boolean& dispatch, Boolean& newChannel)
       在 System.ServiceModel.Channels.ReliableListenerOverSession`5.HandleReceiveComplete(TItem item, TInnerChannel channel)
       在 System.ServiceModel.Channels.ReliableListenerOverSession`5.OnReceiveComplete(IAsyncResult result)
       在 System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
       在 System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
       在 System.ServiceModel.Channels.FramingDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(IAsyncResult result)
       在 System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
       在 System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
       在 System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.OnReceiveComplete(Object state)
       在 System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)
       在 System.ServiceModel.Channels.SocketConnection.FinishRead()
       在 System.ServiceModel.Channels.SocketConnection.AsyncReadCallback(Boolean haveResult, Int32 error, Int32 bytesRead)
       在 System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32 error, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
       在 System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
       在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

    高手有碰到的朋友解答一下,感激不尽!补充一下 wcf服务是使用 .netframework3.5编写的。



    2016年1月13日 5:33
  • 消息处理时出错,建议你单步调试,看看什么时候出的错误。

    另外这个 是不是 有高并发,还是有某些特殊的数据 要服务端处理。

    服务端自己方法内部 有异常处理代码吗


    Frank Xu Lei--谦卑若愚,好学若饥
    [老徐的网站]:http://www.frankxulei.com/

    [老徐的博客]:http://54peixun.com/Author/frankxulei
    微软WCF中文技术论坛
    微软WCF英文技术论坛

    微软WCF技术群:166599314

    2016年2月1日 15:38
    版主