【问题标题】:System.InsufficientMemoryException: Failed to allocate a managed memory buffer of 536870912 bytes. The amount of available memory may be lowSystem.InsufficientMemoryException:无法分配 536870912 字节的托管内存缓冲区。可用内存量可能很低
【发布时间】:2012-10-25 09:55:13
【问题描述】:

下面在服务器端的 Web.Config 中提到。

<bindings>
    <wsHttpBinding>
        <binding name="NewBinding0" closeTimeout="00:50:00" openTimeout="00:50:00" sendTimeout="00:50:00" receiveTimeout="00:50:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            <reliableSession enabled="true" />
            <security mode="None">
                <transport clientCredentialType="None" />
                <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="false" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>

在客户端我也提到了下面的设置。

WSHttpBinding binding = new WSHttpBinding();
//binding.ReaderQuotas.MaxArrayLength = 10485760;
//binding.MaxReceivedMessageSize = 10485760;
binding.Security.Mode = SecurityMode.None;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.Security.Message.EstablishSecurityContext = false;
//binding.Security.Message.NegotiateServiceCredential = true;
binding.ReliableSession.Enabled = true;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
//binding.MaxReceivedMessageSize = 20000000;2147483647
binding.MaxReceivedMessageSize = 2147483647;
//binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
//binding.MaxBufferPoolSize = 20000000;
binding.MaxBufferPoolSize = 2147483647;
//binding.MaxBufferPoolSize = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.SendTimeout = TimeSpan.FromMinutes(50);
binding.CloseTimeout = TimeSpan.FromMinutes(50);
binding.OpenTimeout = TimeSpan.FromMinutes(50);
binding.ReceiveTimeout = TimeSpan.FromMinutes(50);

//EndpointIdentity.CreateUpnIdentity("user@domain");
ChannelFactory<IDBSyncContract> factory = new ChannelFactory<IDBSyncContract>(binding, new EndpointAddress(endPointURL));
dbProxy = factory.CreateChannel();
this.dbProxy = dbProxy as IDBSyncContract;

我遇到了上述错误。

对 wsHttpBindings 有任何顾虑吗?

【问题讨论】:

  • 可能的问题是您的 WCF 配置将许多设置设置为最大整数 2 GB。你有理由进行这些设置吗?
  • 容纳最大数据。有没有办法容纳更多尺寸。通过增加尺寸就足以解决上述问题?

标签: wcf wcf-binding wshttpbinding


【解决方案1】:

您的问题是该服务正在消耗主机上的所有可用内存。我建议您删除 all 您的配置更改并将配置恢复为 WCF 默认值。这些默认值是 Microsoft 选择的,目的是在平均 WCF 服务中获得最佳性能,您应该仅在证明需要时更改它们。

我建议默认值的唯一例外是maxReceivedMessageSizemaxBufferSize 值。我将从 262,144 字节开始。如果您在这些设置中遇到特定异常,则仅更改受影响的设置。

如果您在将设置提高到最大整数后仍然遇到问题,请考虑更改您的服务设计以在正常配置设置内成功调用。尽可能接近 WCF 默认值将为您的服务提供最佳的整体性能。

【讨论】:

    猜你喜欢
    • 2011-03-09
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 1970-01-01
    • 2017-08-07
    • 2012-09-01
    • 1970-01-01
    相关资源
    最近更新 更多