WCF 服务在 30 秒内失败并出现 1 小时超时

发布于 2024-11-27 21:30:26 字数 3483 浏览 0 评论 0 原文

我在本地使用 WCF 服务来计算一些信息,这是 C#,并返回数据。 我返回的数据是浮点数列表 ListListListListListListListList>,一共4个。每个浮动列表包含 400 个项目,每个集合中有 180 个这样的列表。因此,我最初遇到了 4 个 List>

空间不足的错误,然后将大小更新为最大 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 秒内。我正在运行一个单元测试,并且服务正确执行所有操作,并且回复包含有效数据,但是当它返回此回复时,我总是收到此错误。

我一直在搜索,但无法得到任何可以解决的答案,因为我看到的答案只是告诉我增加我拥有的缓冲区/超时。

I am using a WCF Service locally to compute some information, this is C#, and return the data.
The data I am returning is a list of a list of floats List<List< float>>, a total of 4 of these. Each list of floats contains 400 items and there are 180 of these lists in each collection. So 4 of List<List<float>>'s

I originally had an insufficient space error and then updated the size to a maxmimum of 2,000,000 bytes.

<?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.

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'.

Now this timeout occurs within 30 seconds. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪落纷纷 2024-12-04 21:30:26

虽然它被报告为超时异常,但这可能是另一个问题。

您是否尝试设置 maxItemsInObjectGraph 以确保您可以发送大型对象图。

  <serviceBehaviors>

    <behavior name="MyBehavior">

      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>

      <serviceMetadata />

    </behavior>

  </serviceBehaviors>

</behaviors>

只需点击以下链接,希望有帮助:

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

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.

  <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/

溺渁∝ 2024-12-04 21:30:26

正如 @Tim 在他的评论中所建议的,这可能是服务器在大约 30 秒后无法与客户端通信的问题。客户端可能已经关闭了其连接。

确保客户端上的绑定设置与服务器上的绑定设置相匹配。特别是,请确保客户端的 receiveTimeout 值类似于服务器的 sendTimeout

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. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文