wcfwsdualhttpbinding

Wcf wsDualHttpBinding Max message length 16384 reached


I cannot get to work a wsDualHttpBinding endpoint on my WCF service. I'm facing this problem on the client.

I get an exception that suggests to increment MaxArrayLength from 16384 to allow to read the whole xml data.

I tried the following configuration:

 <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="MyBinding" maxReceivedMessageSize="2147483647" />
      </wsDualHttpBinding>
    </bindings>

    <client>
      <endpoint name="WSDualHttpBinding_IDataService" binding="wsDualHttpBinding" bindingConfiguration="MyBinding"
        address="http://localhost:8733/DataProvider/" contract="DataStorageService.IDataService" >
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>

But the above configuration seems to be ignored.

I instantiate my client like this:

  var instanceContext = new InstanceContext( new CallbackHandler() );
  _clientService = new DataServiceClient( instanceContext );

and i read somewhere that these line of codes override the configuration in app.config; if that't the problem, how can i increment quotas?

Any help appreciated.


Solution

  • You do exactly what the error tells you :)

    For this it might be best to see visually how to do it rather than copy and paste code.

    In your project, Right click your service "app.config" and choose "Edit WCF Configuration" from there click on "Bindings" and you should see your custom binding. If not just right click and create a new binding. From here you can change the "ReaderQuotas Properties" what I use is

    MaxArrayLength = 2147483647
    MaxBytesPerRead = 4096
    MaxDepth = 32
    MaxNameTableCharCount = 2147483647
    MaxStringContentLength = 2147483647
    

    Once that is done, go ahead and press "File" and then "Save"

    Now go view your app.config code and it should have updated.

    Run your service and then right click your service references and "Update Service Reference"

    Now if you look at your client app.config file it should match what your service app.config attributes looked like. If this is not the case then right click your clients app.config and "Edit WCF Configuration" again, go to bindings and then choose your service endpoint and change the values to the same as the service.

    Be aware though settings the values that high will leave you vulnerable to ddos attacks etc. so find out what you need and change it after testing.

    Hope this helps :)

    Make sure your service is running as administrator also