Tobias Moe Thorstensen
Tobias Moe Thorstensen

Reputation: 8981

Reading byte array from a SQL database through WCF - maxArrayLength issue

I have a WCF service which is supposed to return a List to my client application. One of the columns in the database are byte[]. When I try to return this list of Object, I only get a NetDispatcherFaultException with this inner-exception:

"The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 38697."

I have googled after this and found a that I should increase the maxArrayLength in the web.config, so I did:

<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"/>
    <add binding="basicHttpBinding" scheme="http" 
         bindingConfiguration="CrudserviceBinding" />
</protocolMapping>

<bindings>
    <basicHttpBinding>
        <binding name="CrudserviceBinding" maxReceivedMessageSize="52428800" >
            <readerQuotas maxStringContentLength="10242880"  
                          maxArrayLength="10242880" />
        </binding>
    </basicHttpBinding>
</bindings>

This is my app.config on the client side:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
              <binding name="BasicHttpBinding_ICrudService">
                <readerQuotas maxStringContentLength="5242880" 
                              maxArrayLength="52428800" />
              </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/My.Project/CrudService.svc"
                      binding="basicHttpBinding" 
                      bindingConfiguration="BasicHttpBinding_ICrudService"
                      contract="MobileCrudService.ICrudService" 
                      name="BasicHttpBinding_ICrudService" />
        </client>
    </system.serviceModel>
</configuration>

When I try this once more, the WCF service returns the same exception. Can anybody explain how I should deal with this?

Upvotes: 0

Views: 272

Answers (1)

sam1589914
sam1589914

Reputation: 816

If you are calling the service in a class Library on the Client, make sure you are changing the actual Application .config file. Do not use

Products/ProductName/Main/Source/Project_Name/bin/Debug/ProjectName.dll.config

instead use

Products/ProductName/Main/Source/Project_EXE_Name/bin/Debug/YourExe.config

Upvotes: 1

Related Questions