22

My Setup:

  • ASP.NET client hosted in IIS Express
  • WCF Service hosted in Console Application
  • Running Visual Studio.NET 2012 in Admin mode

I am trying to return 2 List objects from a WCF service. My setup WORKS FINE when I return just 1 List objects. But when I return 2 List objects I get the 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.

I know that this question has been asked many times on this site and other sites as well. I have tried almost everything posted on the internet with various combinations of the CONFIG FILE but still this has not worked out for me.

Client Config:

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="1572864"/>
    </system.web>

    <system.serviceModel>
        <client>
            <endpoint name="basicHttpBinding"
                address="http://localhost:9502/HCDataService"
                binding="basicHttpBinding"
                bindingConfiguration="basicHttpBinding"                
                contract="HC.APP.Common.ServiceContract.IHCServiceContract"
                behaviorConfiguration="ServiceBehaviour">
            </endpoint>
        </client>

        <bindings>
            <basicHttpBinding>
                <binding name="basicHttpBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </binding>
            </basicHttpBinding>
        </bindings>

        <behaviors>
            <endpointBehaviors>
                <behavior name="ServiceBehaviour">
                    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

Server Config:

<configuration>
    <system.serviceModel>
        <services>
            <service name="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:9502/HCDataService"/>
                    </baseAddresses>
                </host>

                <endpoint name="basicHttpBinding"
                    address="http://localhost:9502/HCDataService"
                    binding="basicHttpBinding"
                    bindingConfiguration="basicHttpBinding"
                    contract="HC.APP.Common.ServiceContract.IHCServiceContract">
                </endpoint>
            </service>
        </services>

        <bindings>
            <basicHttpBinding>
                <binding name="basicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
                    <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </binding>
            </basicHttpBinding>
        </bindings>

        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehaviour">
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceMetadata httpGetEnabled="true" />
                    <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
                </behavior>
            </serviceBehaviors>
        </behaviors>    
    </system.serviceModel>
</configuration>
Yuvi Dagar
  • 649
  • 2
  • 11
  • 20
  • I have updated the both the config file as suggested by Trickery for the benefit of other members. This is now a working solution. One more change that I have made is maxArrayLength="2147483646" on both the configs. And yes the naming of the endpoints can be improved. – Yuvi Dagar Apr 28 '13 at 19:39
  • 2
    Guys, I know this was a duplicate question and mentioned this in my post. The reason I had to post this question (and probably why so many variants of the same question exist), is because WCF configuration is complected and it is VERY EASY to miss out a MINOR DETAIL. I did go through a lot of posts on this site as well as other sites but could not pin point the problem. It required a bit of outside intervention to resolve the problem. So technically my post may sound duplicate, but it differs in the MINOR CONFIG CHANGE that Trickery pointed out. – Yuvi Dagar Apr 29 '13 at 10:57

1 Answers1

38

That would be because you didn't specify on the server which binding to use. Let's take a look at your server config:

Under <bindings> you are creating a binding configuration for <basicHttpBinding>, and you are naming it name="basicHttpBinding". Also, your endpoint name is <endpoint name="basicHttpBinding" ...> and its binding is binding="basicHttpBinding". However, it's not referring to your binding configuration, but to the binding type. So, it's actually using the default settings for basicHttpBinding.

To fix this, first of all name your endpoint and binding configuration differently. For example, <endpoint name="basicEndpoint" ... > and <binding name="myBasicBinding" ... >. Then you need to assign your binding configuration to your endpoint with this attribute: bindingConfiguration="myBasicBinding".

Here's the client config:

<system.web>
    <httpRuntime maxRequestLength="32768"/>
</system.web>

<system.serviceModel>
    <client>
        <endpoint name="basicEndpoint"
            address="http://localhost:9502/HCDataService"
            binding="basicHttpBinding"
            bindingConfiguration="myBasicBinding"
            contract="HC.APP.Common.ServiceContract.IHCServiceContract"
            behaviorConfiguration="ServiceBehaviour">
        </endpoint>
    </client>

    <bindings>
        <basicHttpBinding>
            <binding name="myBasicBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </basicHttpBinding>
    </bindings>

    <behaviors>
        <endpointBehaviors>
            <behavior name="ServiceBehaviour">
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
        </endpointBehaviors>
    </behaviors>    
</system.serviceModel>

Here's the server config:

<system.serviceModel>
    <services>
        <service name="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:9502/HCDataService"/>
                </baseAddresses>
            </host>

            <endpoint name="basicEndpoint"
                address="http://localhost:9502/HCDataService"
                binding="basicHttpBinding"
                bindingConfiguration="myBasicBinding"
                contract="HC.APP.Common.ServiceContract.IHCServiceContract">
            </endpoint>
        </service>
    </services>

    <bindings>
        <basicHttpBinding>
            <binding name="myBasicBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
                <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </basicHttpBinding>
    </bindings>

    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehaviour">
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceMetadata httpGetEnabled="true" />
                <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

Don't forget to update service reference on your client to get the correct config.

Artless
  • 4,522
  • 1
  • 25
  • 40
  • Two things: First, OP needs to apply this to his **client** congif, not the service config. They're encountering this issue when trying to *receive* from the service, not send. Secondly, they did set a name for the binding, they just didn't explicitly set it on the endpoint, as you indicated. – Tim Apr 28 '13 at 18:55
  • Uhh, no. The issue is the server here. Client config just reflects the server's config when he added service reference. Secondly, I never said OP didn't name the stuff, just that he named it in a confusing way and probably why he made the mistake in the first place, as I stated in paragraph 2. – Artless Apr 28 '13 at 18:59
  • Point taken on the naming issue (I missed that when I first read your answer) and I agree. However, this **is** a client issue. `maxReceivedMessageSize`, in this case, applies to the client. The quota settings on the service side have absolutely nothing to do with the quota settings on the client side. Generally it's simpler to keep them the same on both sides, but just because the service can receive. say a 1GB file doesn't mean the client can - unless it's quotas are sufficiently large enough. – Tim Apr 28 '13 at 19:07
  • True. But wouldn't it be much simpler to just tell him to stick that stuff on the server and update service reference? Otherwise, his next question might as well be "why can't I save stuff even though I set maxReceivedMessageSize?" – Artless Apr 28 '13 at 19:11
  • Yes, it would be better to update both configs to avoid any future problems, but if he only updates the service side they'll never get past the current problem. – Tim Apr 28 '13 at 19:15
  • Indeed. That's why I reminded him to update service references in the end as well. **EDIT:** There's no sense arguing over this, I'll just add the client config as well. – Artless Apr 28 '13 at 19:18
  • Trickery, many thanks for a quick turn around. This solved my problem. The WCF config has a lots of small things that can be easily overlooked. – Yuvi Dagar Apr 28 '13 at 19:22
  • 2
    Thanks. The ONLY one answer, which really tackles the question at hand. There is a tone of similar answers to the same question NONE of which is correct. Thanks again @Artless – dpant Oct 06 '16 at 13:46
  • Perfect. Finally an example that lays out the interconnection properly. This should not have been closed as a duplicate when the "other" answers are so poor. Well done. – iCollect.it Ltd Aug 10 '17 at 14:15
  • Thanks. Solved my problem. – Matt Allen Jan 29 '19 at 21:09