2016-08-04 31 views
3

WCFサービスコールを使用して大きなデータをデータベースに保存しようとしています。私はサービスを呼び出すことができません。 ITSは、エラーをスロー:268435456バイトのマネージメモリバッファの割り当てに失敗しました。利用可能なメモリの量が少なくなる可能性があります。

は268435456バイトのマネージメモリバッファの割り当てに失敗しました。

<!-- 
     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 

次の例外: メッセージ:

使用可能なメモリの量が低い

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

サーバー側の設定も可能

268435456バイトの管理メモリバッファの割り当てに失敗しました。使用可能なメモリの量が少なくなる可能性があります。

スタックトレース: サーバースタックトレース: System.Runtime.Fx.AllocateByteArray(のInt32サイズ) でSystem.Runtime.InternalBufferManager.PooledBufferManager.TakeBuffer(のInt32 bufferSizeの) でSystem.ServiceModel.Channels.BufferManagerOutputStreamで。 INIT(のInt32 INITIALSIZE、のInt32 maxSizeQuota、のInt32 effectiveMaxSize、BUFFERMANAGER BUFFERMANAGER)System.ServiceModel.Channels.BufferedMessageWriter.WriteMessageで (メッセージメッセージ、BUFFERMANAGER BUFFERMANAGER、のInt32 initialOffset、のInt32 maxSizeQuota)System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoderで 。 WriteMessage(メッセージメッセージ、Int32 maxMessageSize、BufferManagerバッファマネージャ、Int32 messageOffset)System.ServiceModel.Channels.HttpOutput.SendAsyncResult.Send() でSystem.ServiceModel.Channels.HttpOutput.SendAsyncResult.SendWithoutChannelBindingToken() でSystem.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(メッセージメッセージ、ブールshouldRecycleBuffer) ででSystem.ServiceModel.Channels.HttpOutput.BeginSendCore(HttpResponseMessage httpResponseMessage、のTimeSpanタイムアウト、AsyncCallbackでSystem.ServiceModel.Channels.HttpOutput.SendAsyncResult..ctor(httpOutput httpOutput、HttpResponseMessage httpResponseMessage、ブールsuppressEntityBody、のTimeSpanタイムアウト、AsyncCallbackコールバック、オブジェクト状態) System.ServiceModel.Channels.HttpChannelFactory 1.HttpRequestChannel.HttpChannelAsyncRequest.SendWebRequest() at System.ServiceModel.Channels.HttpChannelFactory 1.HttpRequestChannel.HttpChannelAsyncRequest.BeginSendRequest(メッセージのメッセージ、のTimeSpanタイムアウト)でコールバック、オブジェクト状態) System.ServiceModel.Security.ApplySecurityAndSendAsyncResultで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.Channels.RequestChannel.BeginRequestで(メッセージのメッセージ、のTimeSpanタイムアウト、AsyncCallbackコールバック、状態オブジェクト) 1.Begin(Message message, SecurityProtocolCorrelationState correlationState) at System.ServiceModel.Channels.SecurityChannelFactory 1.SecurityRequestChannel.BeginRequest(メッセージのメッセージ、のTimeSpanタイムアウト、AsyncCallbackコールバック、オブジェクト状態) System.ServiceModel.ChannelsでSystem.ServiceModel.Dispatcher.RequestChannelBinder.BeginRequest(メッセージのメッセージ、のTimeSpanタイムアウト、AsyncCallbackコールバックオブジェクト状態) でSystem.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureOpen(IAsyncResultインター結果、ブーで.ServiceChannel.SendAsyncResult.StartSend(ブールcompletedSynchronously) System.ServiceModel.Channels.ServiceChannelでSystem.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureOpen(ブールcompletedSynchronously) でcompletedSynchronously) を傾きます。System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.BeginでSystem.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureInteractiveInitでSendAsyncResult.FinishEnsureInteractiveInit(IAsyncResultインター結果、ブールcompletedSynchronously) () ()System.ServiceModel.Channels.ServiceChannelで 。 System.ServiceModel.Channels.ServiceChannel.BeginCall(ServiceChannelチャネル、ProxyOperationRuntimeオペレーション、Object [] ins、AsyncCallbackコールバック)で、BeginCall(Stringアクション、Boolean oneway、ProxyOperationRuntimeオペレーション、Object [] ins、TimeSpanタイムアウト、AsyncCallbackコールバック、Object asyncState) 、Object asyncState) at System.Threading.Tasks.TaskFactory 1.FromAsyncImpl[TArg1,TArg2,TArg3](Func 6 beginMethod、Func 2 endFunction, Action 1 endAction、TArg1 arg1、TArg2 arg2、TArg3 arg3、オブジェクト状態、TaskCreationOptions creationOptions) System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateGenericTask(ServiceChannelチャネル、ProxyOperationRuntime動作、オブジェクト[におけるSystem.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateGenericTaskで [T](ServiceChannelチャネル、ProxyOperationRuntime動作は、[]のInputParametersオブジェクト) ]のInputParameters)System.ServiceModelでSystem.ServiceModel.Channels.ServiceChannelProxy.InvokeTaskServiceでSystem.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateTask(ServiceChannelチャネル、IMethodCallMessage methodCallで、ProxyOperationRuntime動作) (IMethodCallMessage methodCallで、ProxyOperationRuntime動作) で。 Channels.ServiceChannelProxy.Invoke(IMessageメッセージ)

例外r RossendaleClient8でSystem.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessageがreqMsg、IMessageがretMsg)で System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(のMessageData & msgData、のInt32型)で :[0]でethrown RossendaleClient8.DAL.RossendaleServiceClient.d__13.MoveNextでRossendaleClient8.DAL.RR.RossendaleServiceClient.UploadResultsAsyncで.DAL.RR.IRossendaleService.UploadResultsAsync(UploadPackageパッケージ) (UploadPackageパッケージ) ()

次に例外: メッセージ:

タイプ 'System.OutOfMemoryException'の例外スローされる。

スタックトレース:System.Runtime.Fx.AllocateByteArray(のInt32サイズ)

+0

データを小さなチャンクに分割し、複数の送信をサービスに行う必要があります。 – Kevin

+0

@ケビンは、全体の多くを送信する方法はありません?それは約200mbです。 – user1800674

+0

サーバにメモリを追加することがあります。しかし、これは本当に問題を解決するとは思わない。ちょうどそれが起こるまでどれくらいの時間をプッシュします。 – Kevin

答えて

0

サンプルです。大きなファイルをアップロードできるように、タイムアウトをmaxAllowedContentを300MBに増やしました。今は素晴らしい作品です。

1

で私はWCFを使用して50メガバイト以上を送信しようとしたことがありませんが、私は256メガバイト+ファイルは簡単のような問題が発生する可能性がかなり確信しています、上記の私はあなたが次のことを試してくださいお勧めしたい:

  • それをしない、ファイルを送信しようとしたときに、ファイルあたり50メガバイト
  • はあなたのサービスのメモリ割り当てを確認してください例えば、小さな小さな塊にあなたのファイルを削除マシン上の使用可能なメモリの最大値を超えていますか?
4

バインディングが許可されている場合は、TransferMode.Streamedを試してください。また、BinaryMessageEncodingをご覧ください。 MSDNから :

  • Buffered transfers hold the entire message in a memory buffer until the transfer is complete.
  • 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.

デフォルトTransferModeがバッファリングされているので、メッセージ全体がメモリにロードされています。Streamed TransferModeをオンにすると、MaxBufferSizeの値を編集してメモリ使用量を管理できます。

BinaryMessageEncodingは、順番に、データを圧縮できます。ネットワーク経由で送信します。上述したように、私は、「ストリーミング」にTransferModeを変更したが、私は最大バッファサイズも増加している前ここ コードで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; 
    } 
0

私たちは最近、同様の問題を持っていた、それは皆のための適切な解決策ではないかもしれません承知だけど、...

。ローカルでいくつかのコードをデバッグする際には、開発者のうちの1人だけが問題を抱えていました彼はの64ビットバージョンのIIS Expressを使用していなかったことが分かります。

関連する問題