首页 > 解决方案 > WCF 错误:套接字连接已中止

问题描述

我使用托管 WCF 连接topshelf和服务配置使用行为和 tcp 连接,如下所示:

<behaviors>
  <serviceBehaviors>
    <behavior name="MetaDataBehvior">
      <serviceMetadata />
    </behavior>
    <behavior>
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
      <security mode="Transport">
        <!--Transport security is enabled Because all machinses on the same Domain (intranet) -->
        <!-- http://www.karthikscorner.com/sharepoint/wcf-transport-security/ -->
        <!--Transport security is enabled-->
          <transport clientCredentialType="Windows"
                    protectionLevel="EncryptAndSign" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>

我什至尝试使用节流,但在多次使用该服务后没有任何变化我收到错误:

发生一个或多个错误。

System.AggregateException:发生一个或多个错误。---> System.ServiceModel.CommunicationException:套接字连接被中止。这可能是由于处理您的消息时出错或远程主机超出接收超时,或者是潜在的网络资源问题造成的。本地套接字超时为“00:00:59.9844041”。---> System.IO.IOException: 写操作失败,见内部异常。---> System.ServiceModel.CommunicationException:套接字连接被中止。这可能是由于处理您的消息时出错或远程主机超出接收超时,或者是潜在的网络资源问题造成的。本地套接字超时为“00:00:59.9844041”。

任何关于如何追踪或解决此问题的建议

标签: c#socketswcfnet-tcp

解决方案


WCF 包含一些可用于跟踪/调试应用程序的类

第一个是启用 Trace logging/message logging,您可以使用 SvcConfigEditor 让您的生活更简单 在此处输入图像描述

然后只需进入 EndToEnd Tracing 部分并编辑配置以满足您的需求,

将跟踪与消息一起使用将为您提供一种将 messageID(一个 guid)与生成的跟踪相关联的方法,并且在某些情况下找到给您带来问题的消息。

您可以检查的另一件事是在您的 ServiceBehavior 设置中启用ServiceAudit标记,这将允许您检查由您的服务产生的安全事件。

在此处输入图像描述


推荐阅读