gpt4 book ai didi

c# - 无法分配268435456字节的托管内存缓冲区。可用内存量可能不足

转载 作者:太空狗 更新时间:2023-10-30 00:23:27 29 4
gpt4 key购买 nike

我正试图通过wcf服务调用将一些大数据保存到数据库中。我无法调用服务。它抛出了一个错误:
未能分配268435456字节的托管内存缓冲区。可用内存可能不足

public async Task<int> UploadExportPackage(DTO.Upload.UploadPackage package)
{
int result = await serviceProxy.UploadResultsAsync(package);
return result;
}

服务器端配置:
    <!-- 
Place limits on the amount of data that can be received in one go.
This helps to protect the server from attack and abuse.
-->
<binding name="primaryBinding"
maxReceivedMessageSize="6000000"
maxBufferSize="6000000"
maxBufferPoolSize="12000000">

<readerQuotas maxArrayLength="6000000"
maxStringContentLength="6000000" />

<!--
Set the security mode. Apply at:
- Transport layer
- Message layer
-->
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpsBinding>
</bindings>

堆栈跟踪:
Exception no: 0 

下一个例外:
消息:
未能分配268435456字节的托管内存缓冲区。可用内存可能不足。
堆栈跟踪:
服务器堆栈跟踪:
在system.runtime.fx.allocateByteArray(Int32大小)
在system.runtime.internalbuffermanager.pooledbuffermanager.takebuffer(int32 buffersize)
位于system.servicemodel.channels.buffermanageroutputstream.init(int32 initialsize,int32 maxsizequeota,int32 effectivemaxsize,buffermanager buffermanager)
位于system.servicemodel.channels.bufferedMessageWriter.writeMessage(消息消息、bufferManager缓冲管理器、int32 initialoffset、int32 maxsizequota)
位于system.servicemodel.channels.textMessageEncoderFactory.textMessageEncoder.writeMessage(消息消息,Int32 MaxMessageSize,BufferManager BufferManager,Int32 MessageOffset)
在system.servicemodel.channels.httpoutput.serializebufferedMessage(消息消息,布尔值shouldcyclebuffer)
位于System.ServiceModel.Channels.HttpOutput.SendAsyncResult.SendWithOutChannelBindingToken()
在System.ServiceModel.Channels.HttpOutput.SendAsyncResult.Send()
在System.ServiceModel.Channels.HttpOutput.SendAsyncResult..ctor(HttpOutput HttpOutput、HttpResponseMessage HttpResponseMessage、Boolean SuppressEntityBody、TimeSpan超时、AsyncCallback回调、对象状态)
在System.ServiceModel.Channels.HttpOutput.BeginSendCore(HttpResponseMessage HttpResponseMessage,TimeSpan超时,异步回调回调,对象状态)
在system.servicemodel.channels.httpchannelfactory 1.HttpRequestChannel.HttpChannelAsyncRequest.SendWebRequest()
at System.ServiceModel.Channels.HttpChannelFactory
1.httprequestchannel.httpchannelasyncrequest.beginsendrequest(消息消息,时间跨度超时)
位于system.servicemodel.channels.requestchannel.beginrequest(消息消息、TimeSpan超时、异步回调回调、对象状态)
在system.servicemodel.channels.securitychannelfactory 1.RequestChannelSendAsyncResult.BeginSendCore(IRequestChannel channel, Message message, TimeSpan timeout, AsyncCallback callback, Object state)
at System.ServiceModel.Security.ApplySecurityAndSendAsyncResult
1.onsecureoutgoingmessagecomplete(消息消息消息)
在system.servicemodel.security.applysecurityandsendasyncresult 1.Begin(Message message, SecurityProtocolCorrelationState correlationState)
at System.ServiceModel.Channels.SecurityChannelFactory
1.securityrequestchannel.beginrequest(消息消息、时间跨度超时、异步回调、对象状态)
在system.servicemodel.dispatcher.requestchannelbinder.beginrequest(消息消息、TimeSpan超时、异步回调、对象状态)
在system.servicemodel.channels.serviceChannel.sendAsyncResult.startSend(同步完成布尔值)
在System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureOpen(IAsyncResult结果,布尔值同步完成)
在System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureOpen(同步完成布尔值)
在System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureInteractiveInit(IAsyncResult结果,布尔值同步完成)
在System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartensureInteractiveInit()
在system.servicemodel.channels.serviceChannel.sendAsyncResult.begin()
在system.servicemodel.channels.servicechannel.begincall(字符串操作、布尔单向、proxyoperationruntime操作、对象[]ins、时间跨度超时、异步回调回调、对象异步状态)
在system.servicemodel.channels.servicechannel.begincall(servicechannel channel,proxyoperationruntime operation,object[]ins,asyncCallback callback,object asyncState)
在system.threading.tasks.taskfactory 1.FromAsyncImpl[TArg1,TArg2,TArg3](Func6 beginmethod,func 2 endFunction, Action1 endaction,target1 arg1,target2 arg2,target3 arg3,对象状态,taskcreationoptions creationoptions)
在system.servicemodel.channels.serviceChannelProxy.taskCreator.createGenerictask[T]上(serviceChannel channel,proxyoperationRuntime操作,对象[]inputParameters)
在system.servicemodel.channels.serviceChannelProxy.taskCreator.createGenerictask(serviceChannel通道,proxyOperationRuntime操作,对象[]inputParameters)
在system.servicemodel.channels.serviceChannelProxy.taskCreator.createtask(serviceChannel频道,imethodCallMessage方法调用,proxyOperationRuntime操作)
在system.servicemodel.channels.serviceChannelProxy.invokeTaskService(imethodCallMessageMethodCall,proxyOperationRuntime操作)
在system.servicemodel.channels.serviceChannelProxy.invoke(IMessage消息)
在[0]重新引发异常:
在Stase.RunTime.ReloTest.Prxess.RealPosial.HuffLeReTurnMessage(Iimessage ReqMsg,Iimessage ReMSG)
在Stase.RunTime.ReloTest.Prxys.RealPosiv.MultuaPookes(MasaGeDATA和MSGDATA,It32类型)
在rossendaleclient8.dal.rr.irossendaleservice.uploadresultsasync(uploadpackage包)
在rossendaleclient8.dal.rr.rossendaleserviceclient.uploadresultsasync(uploadpackage包)
在rossendaleclient8.dal.rossendaleserviceclient.d_u 13.moveNext()
下一个例外:
消息:
引发了“System.OutOfMemoryException”类型的异常。
堆栈跟踪:在system.runtime.fx.allocateByteArray(Int32大小)

最佳答案

如果绑定允许,请尝试使用TransferMode.Streamed。您还可以查看BinaryMessageEncoding
来自MSDN:
缓冲传输将整个消息保存在内存缓冲区中,直到传输完成。
流式传输只缓冲消息头并将消息体作为流公开,从中可以得到较小的部分
一次读一次。
默认的传输模式是缓冲的,所以整个消息都被加载到内存中。如果启用流传输模式,则可以通过编辑maxbuffersize的值来管理内存使用量的大小。
BinaryMessageEncoding则允许您压缩数据,通过网络发送。
下面是app.config内容的示例

 <customBinding>
<binding name="primaryBinding" openTimeout="00:01:00" closeTimeout="00:01:00"
sendTimeout="00:30:00" receiveTimeout="00:30:00">
<binaryMessageEncoding compressionFormat="GZip">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binaryMessageEncoding>
<httpsTransport transferMode="Streamed" maxReceivedMessageSize="6000000"
maxBufferSize="6000000" maxBufferPoolSize="12000000" />
</binding>
</customBinding>

代码中的相同配置
 private Binding GetBinding()
{
var config = new BindingElementCollection();
config.Add(new BinaryMessageEncodingBindingElement()
{
CompressionFormat = CompressionFormat.GZip,
});
config.Add(new HttpsTransportBindingElement()
{
MaxBufferPoolSize = 12000000,
MaxBufferSize = 6000000,
MaxReceivedMessageSize = 6000000,
TransferMode = TransferMode.Streamed,
});

var resultBinding = new CustomBinding(config)
{
OpenTimeout = TimeSpan.FromMinutes(1),
CloseTimeout = TimeSpan.FromMinutes(1),
ReceiveTimeout = TimeSpan.FromMinutes(1),
SendTimeout = TimeSpan.FromMinutes(1),
};

return resultBinding;
}

关于c# - 无法分配268435456字节的托管内存缓冲区。可用内存量可能不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38766714/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com