Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF - The maximum message size quota for incoming messages has been exceeded

I'm getting the following error from my WCF service which is returning the results of a query in C# objects.

The maximum message size quota for incoming messages (131072) has been exceeded

I know how to resolve this via MaxReceivedMessageSize What I'm looking to find out is how do I find out what contributes to the message size. It dosn't look to me like it can be purely data e.g. If I add 5Kb of data to the amount of data I am pulling back from my service. I need to increase MaxReceivedMessageSize by more than 5KB in order to resolve the error.

I'm also wondering about any tools to look at the message size in the debugger. When I step through my code to the point where my WCF service is called, I cant seem to get any info on the message size etc

And finally how to trim/optimise the message size!

like image 310
AJM Avatar asked Jul 16 '09 09:07

AJM


1 Answers

Can you turn on logging? If you include these snippets into your service config:

<system.diagnostics> 
  <sources>
    <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing" >
      <listeners>
         <add name="xmlTrace" 
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="c:\Traces\ServiceTrace.svclog" />
      </listeners>
    </source>
  </sources>
  <trace autoflush="true" />
</system.diagnostics>

<system.serviceModel>
  <diagnostics>
    <messageLogging 
        logMessagesAtTransportLevel="true" logMessagesAtServiceLevel="false" 
        logMalformedMessages="true" logEntireMessage="true" 
        maxSizeOfMessageToLog="65535000" maxMessagesToLog="500" />
  </diagnostics>
</system.serviceModel>

This will create a file ServiceTrace.svclog in the directory you chose. Use the WCF Service Trace Viewer (found in your c:\program files\Microsoft SDKs\Windows\v6.0A\bin\ directory) to analyze the file - it will show you the exact contents of the messages, and also include the "content-length" for the message, so you'll see exactly how big the message is.

like image 180
marc_s Avatar answered Oct 13 '22 11:10

marc_s