无法分配268435456字节的托管内存缓冲区.可用内存量可能不足. [英] Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low.

查看:1066
本文介绍了无法分配268435456字节的托管内存缓冲区.可用内存量可能不足.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我在WPF应用程序中使用WCF服务.这是自托管服务.当我从Visual Studio中运行此服务时,我正在使用 wsHttpBinding 并在服务器中部署时使用 netcpbinding .当我同时使用wshttpbinding从Visual Studio运行时,并从服务器运行时,出现以下错误.我的服务返回的很大像180000 List这样的数据 的对象.请提供解决此错误的解决方案.下面的配置和错误详细信息.

I am using WCF Service in my WPF Application.It is self hosted service.When i ran this from visual studio i am using wsHttpBinding and using netcpbinding when it is deployed in server.I am getting the following error when i ran from both visual studio using wshttpbinding and ran from server.My service is returning large data like 180000 List of Objects.Kindly provide a solution to overcome this error.Below the configuration and error details.

WCF绑定配置:

WCF Binding configuration:

<bindings>
<binding name="NetTcpBindingEndpoint" closeTimeout="00:10:00"
					openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
					transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
					hostNameComparisonMode="StrongWildcard" listenBacklog="10"
					maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10"
					maxReceivedMessageSize="2147483647">
					<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
						maxBytesPerRead="4096" maxNameTableCharCount="16384" />
					<reliableSession ordered="true" inactivityTimeout="00:10:00"
						enabled="false" />
					<security mode="Transport">
						<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
						<message clientCredentialType="Windows" />
					</security>
				</binding>
			</netTcpBinding>
			<wsHttpBinding>
				<binding name="WSHttpBinding_Service" closeTimeout="00:10:00"
					openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
					bypassProxyOnLocal="false" transactionFlow="true" hostNameComparisonMode="StrongWildcard"
					maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
					messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
					allowCookies="false">
					<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
						maxBytesPerRead="4096" maxNameTableCharCount="16384" />
					<reliableSession ordered="true" inactivityTimeout="00:10:00"
						enabled="false" />
					<security mode="Message">
						<transport clientCredentialType="Windows" proxyCredentialType="None"
							realm="" />
						<message clientCredentialType="Windows" negotiateServiceCredential="true"
							algorithmSuite="Default" establishSecurityContext="true" />
					</security>
				</binding>
			</wsHttpBinding>
		</bindings>
<behaviors>
			<endpointBehaviors>
				<behavior name="maxItemsInObjectBehavior">
					<dataContractSerializer maxItemsInObjectGraph="2147483647" />
				</behavior>
			</endpointBehaviors>
		</behaviors>

异常详细信息:

Exception Details:

异常类型: System.InsufficientMemoryException,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089 

Exception Type: System.InsufficientMemoryException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 

消息:无法分配268435456字节的托管内存缓冲区.可用内存量可能不足.

Message: Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low.

堆栈跟踪:

System.Runtime.Fx.AllocateByteArray(Int32大小)
System.Runtime.InternalBufferManager.PooledBufferManager.TakeBuffer(Int32 bufferSize)
System.Runtime.BufferedOutputStream.AllocNextChunk(Int32 minimumChunkSize)
System.Runtime.BufferedOutputStream.WriteCore(Byte []缓冲区,Int32偏移量,Int32大小)
System.Runtime.BufferedOutputStream.Write(Byte []缓冲区,Int32偏移量,Int32大小)
System.Xml.XmlStreamNodeWriter.FlushBuffer()
System.Xml.XmlStreamNodeWriter.UnsafeWriteUTF8Chars(Char * chars,Int32 charCount)
System.Xml.XmlStreamNodeWriter.WriteUTF8Chars(字串值)
System.Xml.XmlUTF8NodeWriter.WriteStartElement(字符串前缀,字符串localName)
System.Xml.XmlUTF8NodeWriter.WriteStartElement(字符串前缀,XmlDictionaryString localName)
System.Xml.XmlSigningNodeWriter.WriteStartElement(字符串前缀,XmlDictionaryString localName)
System.Xml.XmlBaseWriter.WriteStartElement(字符串前缀,XmlDictionaryString localName,XmlDictionaryString namespaceUri)
System.Runtime.Serialization.XmlWriterDelegator.WriteStartElementPrimitive(XmlDictionaryString localName,XmlDictionaryString namespaceUri)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteString(XmlWriterDelegator xmlWriter,字符串值,XmlDictionaryString名称,XmlDictionaryString ns)
WriteAccountSearchDTOToXml(XmlWriterDelegator,Object,XmlObjectSerializerWriteContext,ClassDataContract)
System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter,Object obj,XmlObjectSerializerWriteContext上下文)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract,XmlWriterDelegator xmlWriter,对象obj,RuntimeTypeHandle声明为TypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract,XmlWriterDelegator xmlWriter,对象obj,RuntimeTypeHandle声明为TypeHandle)
系统. WriteArrayOfAccountSearchDTOToXml(XmlWriterDelegator,Object,XmlObjectSerializerWriteContext,CollectionDataContract)
System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter,Object obj,XmlObjectSerializerWriteContext上下文)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract,XmlWriterDelegator xmlWriter,对象obj,RuntimeTypeHandle声明为TypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract,XmlWriterDelegator xmlWriter,对象obj,RuntimeTypeHandle声明为TypeHandle)
系统. WriteResultListOfAccountSearchDTOQ6p0XEGzToXml(XmlWriterDelegator,Object,XmlObjectSerializerWriteContext,ClassDataContract)
System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter,Object obj,XmlObjectSerializerWriteContext上下文)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract,XmlWriterDelegator xmlWriter,对象obj,RuntimeTypeHandle声明为TypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract,XmlWriterDelegator xmlWriter,对象obj,RuntimeTypeHandle声明为TypeHandle)
System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer,对象图,DataContractResolver dataContractResolver)
System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer,对象图,DataContractResolver dataContractResolver)
System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer,对象图,DataContractResolver dataContractResolver)
System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer,对象图)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter编写器,PartInfo部件,对象图)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer,PartInfo部件,对象图)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer,MessageVersion版本,字符串操作,MessageDescription messageDescription,对象returnValue,Object []参数,布尔值isRequest)
System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter编写器,MessageVersion版本,Object []参数,Object returnValue,布尔值isRequest)
System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
System.ServiceModel.Security.SecurityAppliedMessage.WriteBodyToSignThenEncryptWithFragments(流,布尔值includeComments,字符串[]包含前缀,EncryptedData加密的数据,SymmetricAlgorithm算法,XmlDictionaryWriter编写器)
System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.ApplyBodySecurity(XmlDictionaryWriter writer,IPrefixGenerator prefixGenerator)
System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)
System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(消息,BufferManager BufferManager,Int32 initialOffset,Int32 maxSizeQuota)
System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(消息,Int32 maxMessageSize,BufferManager,BufferManager,Int32 messageOffset)
System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(消息消息,布尔值shouldRecycleBuffer)
System.ServiceModel.Channels.HttpOutput.Send(TimeSpan超时)
System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.SendReplyCore(消息消息,TimeSpan超时)
System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.SendReply(消息,TimeSpan超时)
System.ServiceModel.Channels.HttpRequestContext.OnReply(消息消息,TimeSpan超时)
System.ServiceModel.Activation.HostedHttpContext.OnReply(消息消息,TimeSpan超时)
System.ServiceModel.Channels.RequestContextBase.Reply(消息消息,TimeSpan超时)
System.ServiceModel.Channels.SecurityChannelListener`1.SecurityRequestContext.OnReply(消息,TimeSpan超时)
System.ServiceModel.Channels.RequestContextBase.Reply(消息消息,TimeSpan超时)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc& rpc)

System.Runtime.Fx.AllocateByteArray(Int32 size)
System.Runtime.InternalBufferManager.PooledBufferManager.TakeBuffer(Int32 bufferSize)
System.Runtime.BufferedOutputStream.AllocNextChunk(Int32 minimumChunkSize)
System.Runtime.BufferedOutputStream.WriteCore(Byte[] buffer, Int32 offset, Int32 size)
System.Runtime.BufferedOutputStream.Write(Byte[] buffer, Int32 offset, Int32 size)
System.Xml.XmlStreamNodeWriter.FlushBuffer()
System.Xml.XmlStreamNodeWriter.UnsafeWriteUTF8Chars(Char* chars, Int32 charCount)
System.Xml.XmlStreamNodeWriter.WriteUTF8Chars(String value)
System.Xml.XmlUTF8NodeWriter.WriteStartElement(String prefix, String localName)
System.Xml.XmlUTF8NodeWriter.WriteStartElement(String prefix, XmlDictionaryString localName)
System.Xml.XmlSigningNodeWriter.WriteStartElement(String prefix, XmlDictionaryString localName)
System.Xml.XmlBaseWriter.WriteStartElement(String prefix, XmlDictionaryString localName, XmlDictionaryString namespaceUri)
System.Runtime.Serialization.XmlWriterDelegator.WriteStartElementPrimitive(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteString(XmlWriterDelegator xmlWriter, String value, XmlDictionaryString name, XmlDictionaryString ns)
WriteAccountSearchDTOToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )
System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
WriteArrayOfAccountSearchDTOToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , CollectionDataContract )
System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
WriteResultListOfAccountSearchDTOQ6p0XEGzToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )
System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer, PartInfo part, Object graph)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, PartInfo part, Object graph)
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)
System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)
System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
System.ServiceModel.Security.SecurityAppliedMessage.WriteBodyToSignThenEncryptWithFragments(Stream stream, Boolean includeComments, String[] inclusivePrefixes, EncryptedData encryptedData, SymmetricAlgorithm algorithm, XmlDictionaryWriter writer)
System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.ApplyBodySecurity(XmlDictionaryWriter writer, IPrefixGenerator prefixGenerator)
System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)
System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message, Boolean shouldRecycleBuffer)
System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.SendReplyCore(Message message, TimeSpan timeout)
System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.SendReply(Message message, TimeSpan timeout)
System.ServiceModel.Channels.HttpRequestContext.OnReply(Message message, TimeSpan timeout)
System.ServiceModel.Activation.HostedHttpContext.OnReply(Message message, TimeSpan timeout)
System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)
System.ServiceModel.Channels.SecurityChannelListener`1.SecurityRequestContext.OnReply(Message message, TimeSpan timeout)
System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc&amp; rpc)

谢谢

Suresh Rajamani

Suresh Rajamani

推荐答案

>>无法分配268435456字节的托管内存缓冲区.可用内存量可能不足

>> Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low

基于此错误,建议您检查计算机内存是否有限制.

Based on this error, I suggest you check the computer memory whether it is a limit.

从WCF绑定配置中,我发现您使用了Buffered transferMode.缓冲传输将整个消息保存在内存缓冲区中,直到传输完成.我建议您切换到流媒体.流传输仅缓冲邮件头 并将消息主体公开为流,一次可以读取其中的较小部分.

From WCF Binding configuration, I found you used Buffered transferMode. Buffered transfers hold the entire message in a memory buffer until the transfer is complete. I would suggest you switch to Streamed. Streamed transfers only buffer the message headers and expose the message body as a stream, from which smaller portions can be read at a time.

您可以参考下面的链接以获取更多信息.

You could refer the link below for more information.

# https://msdn.microsoft.com/zh-CN/library/system.servicemodel.transfermode(v=vs.110).aspx

# https://msdn.microsoft.com/en-us/library/system.servicemodel.transfermode(v=vs.110).aspx

注意,流仅适用于以下系统定义的绑定:BasicHttpBinding,NetTcpBinding,NetNamedPipeBinding,WebHttpBinding.

Note, Streaming is only available with following system-defined bindings: BasicHttpBinding, NetTcpBinding, NetNamedPipeBinding, WebHttpBinding.

参考: https://msdn.microsoft.com/zh-CN/library/ms733742(v=vs.110).aspx

Reference: https://msdn.microsoft.com/en-us/library/ms733742(v=vs.110).aspx


这篇关于无法分配268435456字节的托管内存缓冲区.可用内存量可能不足.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆