首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >未能分配134217728字节的托管内存缓冲区。可用的内存量可能很低。

未能分配134217728字节的托管内存缓冲区。可用的内存量可能很低。
EN

Stack Overflow用户
提问于 2013-11-26 06:03:00
回答 2查看 13.6K关注 0票数 1

我试图通过WCF服务调用将大量数据保存到数据库中。我无法调用该服务。它抛出一个错误。

代码语言:javascript
运行
复制
codeProxy.SaveCodes(requestHeader, codes, Rawcodes);

未能分配134217728字节的托管内存缓冲区。可用的内存量可能很低。

我已经将服务器和客户端上的web配置配置为最大限制。

客户端web.config

代码语言:javascript
运行
复制
<binding name="WSHttpBinding_dataService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
                    <security mode="None">
                        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
                    </security>
                </binding>

服务器web.config

代码语言:javascript
运行
复制
<service name="ser.WSHttpBinding_dataService" behaviorConfiguration="ServiceBehavior">
      <endpoint contract="ser.IDataservice" binding="wsHttpBinding" bindingConfiguration="datacodeservice" />
      </service>

<wsHttpBinding>
        <binding name="datacodeservice" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
          <security mode ="None">
            <!--<message clientCredentialType="Certificate" />-->
          </security>
        </binding>


<serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceThrottling maxConcurrentSessions="100" />
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>

        </behavior>
      </serviceBehaviors>
EN

回答 2

Stack Overflow用户

发布于 2013-11-26 06:51:19

在WCF操作的消息契约中使用Stream属性来传输大对象。

代码语言:javascript
运行
复制
[MessageContract]
public class DocumentDescription
{
    [MessageBodyMember(Namespace = "http://example.com/App")]
    public Stream Stream { get; set; }
}

以这种方式配置绑定

代码语言:javascript
运行
复制
<binding name="Binding_DocumentService" receiveTimeout="03:00:00"
        sendTimeout="02:00:00" transferMode="Streamed" maxReceivedMessageSize="2000000">
    <security mode="Transport" />
</binding>

要将大型数据上载到Server数据库,请使用以下文章通过ASP.Net MVC从Server下载和上传图像中描述的方法

票数 1
EN

Stack Overflow用户

发布于 2014-06-11 14:47:53

如果您在.Net 2.0服务中遇到此问题,此修补程序可能会有所帮助

http://support.microsoft.com/kb/974065

问题 当您运行基于.NET Framework2.0的应用程序时,应用程序会崩溃.如果调试应用程序,则会注意到抛出了System.InsufficientMemoryException异常。然后,您将收到一条类似于以下内容的错误消息:未能分配字节的托管内存缓冲区。可用的内存量可能很低。 原因 问题1的原因 当应用程序试图为大对象堆(LOH)中的大型对象分配内存时,会间歇性地发生此问题。当下列条件为真时,将触发错误消息:堆不能提供足够的内存来满足LOH分配请求。同时正在进行并发垃圾收集。问题2的原因 发生此问题的原因是,对于小对象分配的垃圾收集器堆平衡没有在拥有8个以上逻辑处理器的计算机上执行。因此,当不同处理器的工作负载不平衡时,就会触发更多的垃圾回收来保持堆平衡。因此,应用程序花费更多的时间在垃圾收集上。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20209641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档