简体   繁体   English

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

[英]WCF Service fails with a 1 hour timeout in 30 seconds

I am using a WCF Service locally to compute some information, this is C#, and return the data. 我在本地使用WCF服务来计算一些信息(这是C#)并返回数据。 The data I am returning is a list of a list of floats List<List< float>> , a total of 4 of these. 我返回的数据是浮点List<List< float>> ,总共4个。 Each list of floats contains 400 items and there are 180 of these lists in each collection. 每个花车列表包含400个项目,每个集合中有180个这些列表。 So 4 of List<List<float>> 's 所以List<List<float>>的4

I originally had an insufficient space error and then updated the size to a maxmimum of 2,000,000 bytes. 我最初没有足够的空间错误,然后将大小更新为最大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>

I also have updated this in my host manually setting these values. 我还在主机中手动设置了这些值,对此进行了更新。

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();
}

I have also set the timeouts to 1 hr and 10 minutes. 我还将超时设置为1小时10分钟。

The error I get is The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '01:09:59.9770000'. 我得到的错误是The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '01:09:59.9770000'. The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '01:09:59.9770000'.

Now this timeout occurs within 30 seconds. 现在,此超时发生在30秒内。 I have a unit test I am running and the Service does everything correctly and the reply contains valid data, however when it returns this reply I always get this error. 我正在运行一个单元测试,并且服务正确执行了所有操作,并且答复包含有效数据,但是当它返回此答复时,我总是会收到此错误。

I have been searching and I cannot get any answer that resolves as the ones I have seen just inform me to increase the buffer/timeouts which I have. 我一直在搜索,但无法得到任何解决的答案,因为我看到的答案只是通知我增加我拥有的缓冲区/超时。

Although it's reported as time out exception, it may be another issue. 尽管它被报告为超时异常,但这可能是另一个问题。

Would you try Set set the maxItemsInObjectGraph to make sure that you can send a large object graph. 您是否会尝试通过Set设置maxItemsInObjectGraph来确保可以发送大型对象图。

  <serviceBehaviors>

    <behavior name="MyBehavior">

      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>

      <serviceMetadata />

    </behavior>

  </serviceBehaviors>

</behaviors>

Just follow the following link, wish it helps: 只需点击以下链接,希望对您有所帮助:

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

As @Tim suggested in his comment, this might be a problem of the server not being able to talk to the client after ~30 seconds. 正如@Tim在他的评论中建议的那样,这可能是服务器在约30秒后无法与客户端进行通信的问题。 The client may have already closed its connection. 客户端可能已经关闭其连接。

Make sure that the binding settings on the client match those of the server. 确保客户端上的绑定设置与服务器上的绑定设置匹配。 Especially, make sure that the client's receiveTimeout value resembles the server's sendTimeout . 特别是,请确保客户端的receiveTimeout值类似于服务器的sendTimeout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM