WCF - Maximum message size quota exceeded for incoming messages

I get the following error from my WCF service, which returns query results in C # objects.

Maximum message size quota for incoming messages (131072) exceeded

I know how to resolve this with MaxReceivedMessageSize . I am looking to learn how to find out what contributes to message size. He does not look at me as if it could be purely data, for example. If I add 5Kb of data to the amount of data that I return from my service. I need to increase MaxReceivedMessageSize by more than 5 KB to fix the error.

I am also interested in what tools will look for message size in the debugger. When I look through my code until the moment my WCF service is called, I cannot get information about the size of the message, etc.

And finally, how to crop / optimize message size!

+7
web-services wcf
source share
2 answers

Can you turn on logging? If you include these fragments in the service configuration:

<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 the ServiceTrace.svclog file in the directory of your choice. Use the WCF trace viewer (found in your directory c:\program files\Microsoft SDKs\Windows\v6.0A\bin\ ) to analyze the file - it will show you the exact contents of the messages and also include the "length of the content" for the message, so that you will see exactly how big the message is.

+10
source share

You can use the Serializer Data Contract Serializer to serialize a message into a MemoryStream, and then check how many bytes are.

0
source share

All Articles