Yeti
Yeti

Reputation: 21

The maximum message size quota for incoming messages (65536) has been exceeded. Silverlight+ WCF

I've bean searching for whole day for solution to my problem (on StackOverflow also) but unforntunately nothing worked. I'm still getting error:

"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."

There are hundreds of solutions but based on having .config file in project. I have got a WCF service and Silverlight client. The bindings between them are set programmatically only.

Here's the chunk code for WCF service configuration:

private ServiceHostBase CreateService(Uri baseAddress)
    {
        var serviceHost = new ServiceHost(typeof(MyService), new[] { baseAddress });
        var endPointWithoutSSL = new BasicHttpBinding()
        {
            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
            MaxBufferPoolSize = int.MaxValue,
        };

        serviceHost.AddServiceEndpoint(typeof(MyService), endPointWithoutSSL,                                       baseAddress.ToString());
        return serviceHost;
    }

In Silverlight project configuration of client endpoint looks like this:

private BasicHttpBinding GetBinding()
    {
        var securityMode = GetSecurityMode();
        var binding = new BasicHttpBinding(securityMode)
        {
            SendTimeout = TimeSpan.FromMinutes(10),
            OpenTimeout = TimeSpan.FromMinutes(10),
            CloseTimeout = TimeSpan.FromMinutes(10),
            ReceiveTimeout = TimeSpan.FromMinutes(10),
            TextEncoding = Encoding.UTF8,
            TransferMode = TransferMode.Buffered,
            MaxReceivedMessageSize = int.MaxValue,
            MaxBufferSize = int.MaxValue,
        };

        return binding;
    }

No matter how hard I try, the MaxReceivedMessageSize is set to 65k from client side. Microsoft WCF trace tool shows that, after throwing exception about exceeding the max received message size.

What's more interesting, enabling BasicHttpSecurityMode.Transport in endpoint doesn't cause this error. However, I have to set my endpoints without BasicHttpSecurityMode.Transport option.

Any help would be appreciated.

Thanks

Upvotes: 0

Views: 1683

Answers (1)

Cem Sönmez
Cem Sönmez

Reputation: 516

Try below code in WCF side, it should work.

    private ServiceHostBase CreateService(Uri baseAddress)
    {
        var serviceHost = new ServiceHost(typeof(MyService), new[] { baseAddress });
        var endPointWithoutSSL = new BasicHttpBinding()
        {
            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
            MaxBufferPoolSize = int.MaxValue,
        };

        endPointWithoutSSL.ReaderQuotas.MaxStringContentLength = int.MaxValue;
        endPointWithoutSSL.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
        endPointWithoutSSL.ReaderQuotas.MaxDepth = int.MaxValue;
        endPointWithoutSSL.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
        endPointWithoutSSL.ReaderQuotas.MaxArrayLength = int.MaxValue;

        serviceHost.AddServiceEndpoint(typeof(MyService), endPointWithoutSSL, baseAddress.ToString());
        return serviceHost;
    }

Upvotes: 2

Related Questions