WCF:尽管超时值较大,但套接字连接已中止

时间:2018-06-29 12:39:30

标签: c# wcf

尽管配置了较大的超时值,但我仍然收到“套接字连接已中止。这可能是由于错误处理消息或远程主机超出了接收超时或潜在的网络资源问题引起的。本地套接字超时为“ 10:10:10”。”

我的客户端web.config看起来像这样:

<bindings>
      <customBinding>      
        <binding name="HttpBinding" openTimeout="1:00:00" sendTimeout="1:00:00" receiveTimeout="01:00:00" closeTimeout="1:00:00">
          <binaryMessageEncoding>
            <readerQuotas maxDepth="4194304" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />
          </binaryMessageEncoding>
          <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
        </binding>    
   <binding name="CustomNetTcpBindingConfig" openTimeout="1:00:00" sendTimeout="1:00:00" receiveTimeout="1:00:00" closeTimeout="1:00:00" maxStringContentLength="2147483647"  maxArrayLength="2147483647" maxBytesPerRead="4194304" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" >
        <binaryMessageEncoding compressionFormat="GZip">    
<readerQuotas maxDepth="4194304" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />       
         </binaryMessageEncoding>
             <windowsStreamSecurity protectionLevel="None" />     
        <tcpTransport /> 
    </binding>
      </customBinding>
      <netTcpBinding>
        <binding name="NetTcpBinding_IDataUploader" closeTimeout="10:01:00" openTimeout="11:01:00" receiveTimeout="11:10:00" sendTimeout="11:01:00" transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="10000000" maxBufferSize="100000000" maxConnections="10" maxReceivedMessageSize="100000000">
          <readerQuotas maxDepth="4194304" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />
          <reliableSession ordered="true" inactivityTimeout="10:10:00" enabled="false" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
  </netTcpBinding>
    </bindings>

<endpoint address="net.tcp://corp.address.com/FileTransferService" binding="customBinding" bindingConfiguration="CustomNetTcpBindingConfig" contract="Intel.ATRMS.IDataUploader" name="NetTcpBinding_IDataUploader">
        <identity>
          <servicePrincipalName value="" />
          <dns value="corp.address.com" />
        </identity>
      </endpoint>

 <behaviors>
      <endpointBehaviors>
        <behavior name="ClientBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MTServiceBehavior">
          <serviceMetadata httpGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="True" />
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
          <serviceThrottling maxConcurrentCalls="75" maxConcurrentSessions="75" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

我的服务器端配置如下:

 <configuration>
      <system.serviceModel>
        <services>
          <service behaviorConfiguration="StreamsBehaviour"
            name="data.StreamedFileTransfer.StreamHandler">

            <endpoint address="" binding="customBinding" bindingConfiguration="CustomNetTcpBindingConfig"
              contract="data.StreamedFileTransfer.IDataUploader" name="NetTcpBinding_IDataUploader">
          <identity>
            <dns value="corp.address.com" />
          </identity>
        </endpoint>

        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />

        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://corp.address.com/FileTransferService" />
          </baseAddresses>
        </host>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="StreamsBehaviour">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <netTcpBinding>
        <binding
        openTimeout="01:00:00"
        closeTimeout="01:00:00"
        receiveTimeout="01:00:00"
        sendTimeout="01:00:00"
        transferMode="Streamed"
        maxBufferPoolSize="524288"
        maxBufferSize="2147483647"
        maxReceivedMessageSize="2147483647"
        name="MainBinding">
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows"/>
          </security>

        </binding>

      </netTcpBinding>
<customBinding>
<binding name="CustomNetTcpBindingConfig" closeTimeout="1:00:00" openTimeout="1:00:00" receiveTimeout="1:00:00" sendTimeout="1:00:00"       maxBufferPoolSize="524288"
        maxBufferSize="2147483647"    maxReceivedMessageSize="2147483647">
     <windowsStreamSecurity  protectionLevel="None" />    
 <binaryMessageEncoding compressionFormat="GZip">
<readerQuotas maxDepth="4194304" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" />       
</binaryMessageEncoding>
 <tcpTransport /> 
    </binding>
</customBinding>
    </bindings>
  </system.serviceModel>

经历了关于stackoverflow的大多数解决方案。但是我仍然遇到同样的错误。

我推荐的一些论坛站点

  1. https://social.msdn.microsoft.com/Forums/vstudio/en-US/ed0fd370-fa14-4c40-8068-4327786f1f49/the-socket-connection-was-aborted-this-could-be-caused-by-an-error-processing-your-message-or-a?forum=wcf
  2. https://www.codeproject.com/Questions/633699/Socket-Exception-WCF

编辑:

  1. 仅适用于100 MB之类的大文件失败。但我能够上传10 KB文件。
  2. 将所有属性值(例如(MaxItemsInObjectGraph,MaxReceivedMessageSize,MaxBufferPoolSize,MaxBufferSize,MaxArrayLength))设置为最大值。

请指导我。

0 个答案:

没有答案