9

When I call a WCF service I get an exception:

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

When I use Wireshark packet analyzer filter on http the larges packet sent is 1226 bytes, which is way bellow the limit of 65536 bytes. Any suggestions to why this exception is thrown?

Screendump from wireshark

Protocol-Length-Info

Server stack trace:

at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
... 
    <binding 
        name="WSHttpBinding_IService" 
        closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        bypassProxyOnLocal="false" 
        transactionFlow="false" 
        hostNameComparisonMode="StrongWildcard"
        maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
        allowCookies="false">
        <readerQuotas 
          maxDepth="32" 
          maxStringContentLength="8192" 
          maxArrayLength="16384"
          maxBytesPerRead="4096" 
          maxNameTableCharCount="16384" />
        <reliableSession 
          ordered="true" 
          inactivityTimeout="00:10:00"
          enabled="false" />
        <security 
          mode="Message">
          <transport 
            clientCredentialType="Windows" 
            proxyCredentialType="None"
            realm="" />
        <message 
          clientCredentialType="Certificate" 
          negotiateServiceCredential="true"
          algorithmSuite="Default" />
      </security>
    </binding>

Code that I suspect causes the exception:

public LoanPlan CalculateLoanPlans(string productName)
{
    var loanPlan = new LoanPlan
    {
        Details = new[]
        {
            new PlanDetails {LoanAmount = 5000, Periods = 6},
            new PlanDetails {LoanAmount = 5000, Periods = 12},
            new PlanDetails {LoanAmount = 5000, Periods = 24},

            new PlanDetails {LoanAmount = 10000, Periods = 6},
            new PlanDetails {LoanAmount = 10000, Periods = 12},
            new PlanDetails {LoanAmount = 10000, Periods = 24},

            new PlanDetails {LoanAmount = 15000, Periods = 6},
            new PlanDetails {LoanAmount = 15000, Periods = 12},
            new PlanDetails {LoanAmount = 15000, Periods = 24},

            new PlanDetails {LoanAmount = 20000, Periods = 6},
            new PlanDetails {LoanAmount = 20000, Periods = 12},
            new PlanDetails {LoanAmount = 20000, Periods = 24},

            new PlanDetails {LoanAmount = 30000, Periods = 6},
            new PlanDetails {LoanAmount = 30000, Periods = 12},
            new PlanDetails {LoanAmount = 30000, Periods = 24},

            new PlanDetails {LoanAmount = 40000, Periods = 6},
            new PlanDetails {LoanAmount = 40000, Periods = 12},
            new PlanDetails {LoanAmount = 40000, Periods = 24},

            new PlanDetails {LoanAmount = 50000, Periods = 6},
            new PlanDetails {LoanAmount = 50000, Periods = 12},
            new PlanDetails {LoanAmount = 50000, Periods = 24}
        },
        TaxProcent = _taxPercent,
     };
     Parallel.ForEach(loanPlan.Details, detail =>
     {
         var result = Calculate(productName, Convert.ToInt32(detail.LoanAmount), detail.Periods, null);

         detail.ActualPaymentCost = result.ActualPaymentCost;
         detail.CreditCost = result.CreditAmount;
         detail.MonthlyPayment = result.MonthlyPayment;
         detail.MonthlyPaymentCost = result.MonthlyPaymentCredit;
     });

     var firstDetail = loanPlan.Details[0];
     var firstResult = Calculate(productName, Convert.ToInt32(firstDetail.LoanAmount), firstDetail.Periods, null);

     loanPlan.MonthlyFee = firstResult.MonthlyFee;
     loanPlan.MonthlyInterest = firstResult.MonthlyInterest;

     return loanPlan;
}

The Calculate method contains the servicecall.

7
  • 1
    Can you post your config entries?
    – Rajesh
    Commented Feb 23, 2012 at 10:09
  • 1
    Also please set the following readerQuotas within your binding element in your config on both client and server: <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="64" maxNameTableCharCount="2147483647" /> and the datacontract serializer in your behaviorconfiguration element : <dataContractSerializer maxItemsInObjectGraph="2147483647" /> and set the maxRecievedMessageSize as shown: <binding name="mybinding" maxReceivedMessageSize="2147483647">
    – Rajesh
    Commented Feb 23, 2012 at 10:09
  • Doesn't the error come from the server reply rather than your request?
    – adrianm
    Commented Feb 23, 2012 at 10:11
  • You need to have the same settings on both client and server
    – Rajesh
    Commented Feb 23, 2012 at 10:12
  • 2
    Why is the instinctive reaction of most, when faced with such problems of lengths in WCF, to suggest limiting all length-related properties to no less than their maximum capacity? Commented Feb 23, 2012 at 10:18

1 Answer 1

1

Increase maxStringContentLength & maxArrayLength="2147483647" on both server and client. Check the below link which explains in detail

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f570823a-8581-45ba-8b0b-ab0c7d7fcae1

6
  • I think the question is not how to fix it, but why it happens Commented Feb 23, 2012 at 10:20
  • 2
    And this is a very temperamental fix, at best. Commented Feb 23, 2012 at 10:21
  • I have done that on the client. I want to be sure that this is the problem before i make the serverside people change the config. The strange thing is that i cannot see any packages larger than the limit being sent when i use wireshark.
    – espvar
    Commented Feb 23, 2012 at 10:25
  • Yes you need to increase on both Server & Client. Commented Feb 23, 2012 at 10:35
  • The thing is that i suspect that it's the message size that is the real problem. Because it works for a short while, but when i run a specific method that makes a specific call to the service I get the exception. An the Methods that did work before now also throws the same exception. I added a code snippet to my post that explains what call i suspect is causing it.
    – espvar
    Commented Feb 23, 2012 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.