2

I have a WCF file transfer service that is throwing QuotaExceededException when my file is bigger than 1.5 GB. I've reviewed similar posts but I'm not understanding why I'm getting the exception or how to resolve it.

System.ServiceModel.QuotaExceededException: The maximum message size quota for incoming messages (2147483647) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Here's a snip of my client app.config:

<basicHttpBinding>
    <binding name="BasicHttpBinding_IFileTransfer" 
             maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" 
             transferMode="Streamed" 
             receiveTimeout="00:30:00" sendTimeout="01:30:00" 
             openTimeout="00:30:00" closeTimeout="00:30:00">
        <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
                      maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                      maxNameTableCharCount="16384"/>
    </binding>
</basicHttpBinding>

Here's a snip of my web.config:

<basicHttpBinding>
    <binding name="FileTransfer" maxReceivedMessageSize="2147483647" 
             maxBufferSize="2147483647" transferMode="Streamed" 
             receiveTimeout="00:30:00" sendTimeout="01:30:00" 
             openTimeout="00:30:00" closeTimeout="00:30:00">
        <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
                      maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                      maxNameTableCharCount="16384"/>
    </binding>
</basicHttpBinding>

Here's a snip of the service code that's throwing the exception:

var sum = 0;  

try  
{  
    FileStream targetStream;  
    var sourceStream = request.FileByteStream;  

    using (targetStream = new FileStream(tfile, FileMode.Create, FileAccess.Write, FileShare.None))  
    {  
        const int bufferLen = 1024 * 64;  
        var buffer = new byte[bufferLen];  
        int count;  

        while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)  
        {  
            targetStream.Write(buffer, 0, count);  
            sum += count;  
        }  

        targetStream.Close();  
        sourceStream.Close();  
    }  
}  
catch (Exception ex)  
{  
    Logger.Debug("sum = " + sum);  // sum = 1610609664 bytes (this is 1.499997 GB)  
    Logger.LogException(ex);  
}  

I can't get anything larger that 1.5 GB

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
fuchs_tx
  • 135
  • 1
  • 6
  • 1
    The `maxReceivedMessageSize` is the total data transferred, including all headers and the size of the data as it is actually transferred. If transferring as a soap message and the data is being Base64 encoded for example, the actual data transferred is going to have a lot of overhead, so you probably are hitting that 2GB limit with a 1.5GB file. You need to increase the limit (it will take Int64.MaxValue, but possibly only in code for the binding, see http://stackoverflow.com/questions/1004717/what-is-the-maximum-size-that-maxreceivedmessagesize-can-be-set-to-for-a-netname) – steve16351 Jun 19 '16 at 19:11

1 Answers1

2

Thanks steve16351, I didn't realize that maxReceivedMessageSize was a long. I updated my config files with Int64.MaxValue (9223372036854775807) and was able to upload a 6.8 GB file.

<basicHttpBinding>
    <binding name="FileTransfer" maxReceivedMessageSize="9223372036854775807" maxBufferSize="2147483647" transferMode="Streamed" receiveTimeout="00:30:00" sendTimeout="01:30:00" openTimeout="00:30:00" closeTimeout="00:30:00">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
    </binding>
</basicHttpBinding>

And I changed my sum to a long, works great now.

var sum = 0L;  
try  
{  
    FileStream targetStream;  
    var sourceStream = request.FileByteStream;  
    using (targetStream = new FileStream(tfile, FileMode.Create, FileAccess.Write, FileShare.None))  
    {  
        const int bufferLen = 1024 * 64;  
        var buffer = new byte[bufferLen];  
        int count;  
        while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)  
        {  
            targetStream.Write(buffer, 0, count);  
            sum += count;  
        }  
        targetStream.Close();  
        sourceStream.Close();  
    }  
}  
catch (Exception ex)  
{  
    Logger.Debug("sum = " + sum);  // no more exception  
    Logger.LogException(ex);  
}  
fuchs_tx
  • 135
  • 1
  • 6