c# – WCF服务失败,在30秒内超时1小时

我在本地使用WCF服务来计算一些信息,这是C#,并返回数据.

我返回的数据是一个浮动列表列表< List< float>&gt ;,总共4个.每个浮动列表包含400个项目,每个集合中有180个这样的列表.所以List< List< float>>的4

我最初没有足够的空间错误,然后将大小更新为最大2,000,000字节.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="NetTcpBinding_IExternalBallistics" closeTimeout="01:10:00"
                openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00"
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="2000000" maxBufferSize="2000000" maxConnections="10"
                maxReceivedMessageSize="2000000">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                    <message clientCredentialType="Windows" />
                </security>
            </binding>
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://localhost:6100/ExternalBallistics"
            binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IExternalBallistics"
            contract="IExternalBallistics" name="NetTcpBinding_IExternalBallistics" />
    </client>
</system.serviceModel>
</configuration>

我也在我的主机中手动设置了这些值.

private void InitializeServiceHost()
{
    if (_serviceHost != null)
    {
        _serviceHost.Close();
    }

    Uri address = new Uri("net.tcp://localhost:6100/ExternalBallistics");
    NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
    binding.MaxReceivedMessageSize = 2000000;
    binding.MaxBufferSize = 2000000;
    binding.MaxBufferPoolSize = 2000000;
    binding.CloseTimeout = new TimeSpan(1, 10, 0);
    binding.OpenTimeout = new TimeSpan(1, 10, 0);
    binding.ReceiveTimeout = new TimeSpan(1, 10, 0);
    binding.SendTimeout = new TimeSpan(1, 10, 0);
    _serviceHost = new ServiceHost(typeof(ExternalBallisticsImpl), address);
    _serviceHost.Description.Behaviors.Add(GetMetadataBehavior());
    _serviceHost.CloseTimeout = new TimeSpan(1, 10, 0);
    _serviceHost.OpenTimeout = new TimeSpan(1, 10, 0);
    _serviceHost.AddServiceEndpoint(typeof(IExternalBallistics), binding, address);
    _serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), "mex");

    _serviceHost.Open();
}

我还将超时设置为1小时10分钟.

我得到的错误是
套接字连接已中止.这可能是由于处理消息的错误或远程主机超出接收超时或基础网络资源问题引起的.本地套接字超时为’01:09:59.9770000′.

现在这个超时发生在30秒内.我有一个单元测试我正在运行,服务正确地执行所有操作,并且回复包含有效数据,但是当它返回此回复时,我总是收到此错误.

我一直在寻找,我无法得到任何解决,因为我看到的只是通知我增加我的缓冲/超时.

最佳答案 虽然它被报告为超时例外,但它可能是另一个问题.

您是否尝试Set set the maxItemsInObjectGraph以确保您可以发送大对象图.

  <serviceBehaviors>

    <behavior name="MyBehavior">

      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>

      <serviceMetadata />

    </behavior>

  </serviceBehaviors>

</behaviors>

只需按照以下链接,希望它有所帮助:

http://davybrion.com/blog/2008/09/wcf-and-large-amounts-of-data/

点赞