views:

957

answers:

2

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!

A: 

You could use the Data Contract Serializer to serialize the message to a MemoryStream, then check to see how many bytes that amounts to.

John Saunders
+5  A: 

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.

Marc

marc_s
Where can I find the "content-length" information, I have the Microsoft Service Trace Viewer open and don't see it...
manu08