我试图通过WCF服务调用将大量数据保存到数据库。我无法调用该服务。它抛出了一个错误。
codeProxy.SaveCodes(requestHeader, codes, Rawcodes);
无法分配134217728字节的托管内存缓冲区。该 可用内存量可能很低
我已将服务器和客户端的Web配置配置为最大限制。
客户端web.config
<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>
server web.config
<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>
答案 0 :(得分:1)
在WCF操作的消息合约中使用Stream属性来传输大对象。
[MessageContract]
public class DocumentDescription
{
[MessageBodyMember(Namespace = "http://example.com/App")]
public Stream Stream { get; set; }
}
以这种方式配置绑定
<binding name="Binding_DocumentService" receiveTimeout="03:00:00"
sendTimeout="02:00:00" transferMode="Streamed" maxReceivedMessageSize="2000000">
<security mode="Transport" />
</binding>
将大数据上传到以下文章Download and Upload images from SQL Server via ASP.Net MVC
中描述的SQL Server数据库使用方法答案 1 :(得分:1)
如果您在.Net 2.0服务上遇到此问题,此修补程序可能会有所帮助
http://support.microsoft.com/kb/974065
问题
当您运行基于.NET Framework 2.0的应用程序时, 应用程序崩溃。如果您调试应用程序,您会注意到a 抛出System.InsufficientMemoryException异常。那么你 收到类似于以下内容的错误消息:失败 分配一个字节的托管内存缓冲区。可用金额 记忆可能很低。
原因
问题1的原因
应用程序尝试时间歇性地发生此问题 为大对象堆(LOH)中的大对象分配内存。该 满足以下条件时触发错误消息: 堆不能提供足够的内存来满足LOH分配 请求。并发垃圾收集正在进行中 时间。问题2的原因
发生此问题是因为垃圾收集器堆平衡较小 对象分配不会在具有的计算机上勤奋地执行 超过8个逻辑处理器。正因为如此,更多垃圾 当存在时,触发集合以维持堆平衡 不同处理器的工作负载不平衡。因此, 应用程序将更多时间花在垃圾收集上。