Thursday, January 5, 2012

WCF error while communicating large data : Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low.

This error generally comes when communicating a lot of data , say 200, 300 MBs or above.

To avoid this error set transfermode attribute to "streamed" rather than "Buffered" (default value)

like below:


<basicHttpBinding>
  <binding name="HttpStreaming" maxReceivedMessageSize="67108864"
           transferMode="Streamed"/>
</basicHttpBinding>
<!-- an example customBinding using Http and streaming-->
<customBinding>
  <binding name="Soap12">
    <textMessageEncoding messageVersion="Soap12WSAddressing10" />
    <httpTransport transferMode="Streamed" maxReceivedMessageSize="67108864"/>
  </binding>
</customBinding>
 
transfermode should be set both at client and server sides.
for more information please see: http://msdn.microsoft.com/en-us/library/ms789010.aspx

1 comment:

  1. This will not work without a change in code if below is not true.
    At least one of the types of the parameter and return value must be either Stream, Message, or IXmlSerializable.

    ReplyDelete