openshac
openshac

Reputation: 5165

The maximum nametable character count quota (16384) has been exceeded

I've just increased the number of methods in my ServiceContract. when I update the Service Reference in Visual Studio I get the message:

Metadata contains a reference that cannot be resolved: 'net.tcp://xxxxx.com:8002/DataQueryService/mex'.

There is an error in the XML document.

The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

The original server side config was:

 <services>
      <service behaviorConfiguration="XXXXX.DataQueryService.ServiceBehavior" name="XXXXX.DataQueryService.QueryService">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://xxxxx.com:8002/DataQueryService" />
          </baseAddresses>
        </host>
        <endpoint name="MexEndpoint" address="mex" binding="customBinding" bindingConfiguration="unsecureTcpMex" contract="IMetadataExchange" />
    </service>
</services>

<bindings>
    <customBinding>
        <binding name="unsecureTcpMex">
            <tcpTransport portSharingEnabled="True" />
        </binding>
    </customBinding>    
</bindings>

which I modified to:

<bindings>
    <customBinding>
        <binding name="unsecureTcpMex">
            <textMessageEncoding>
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </textMessageEncoding>
            <tcpTransport portSharingEnabled="True" maxReceivedMessageSize="2147483647"  />
        </binding>
    </customBinding>    
</bindings>

What other changes do I need to make to my config to get this working?

Update Following @Chris's advice I tried updating the config file for SVCUtil. I added a name to my endpoint so that it would match (updated above). The SvcUtil.config is now as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="unsecureTcpMex">
                    <textMessageEncoding>
                        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    </textMessageEncoding>
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint binding="customBinding" bindingConfiguration="unsecureTcpMex"
                contract="IMetadataExchange"
                name="MexEndpoint" />
        </client>
    </system.serviceModel>
</configuration>

Upvotes: 5

Views: 4122

Answers (4)

Bart Calixto
Bart Calixto

Reputation: 19725

<binding name="NameSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text">
    <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="1638400" />
    <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
</binding>

Take a look to this line: maxNameTableCharCount="1638400"

Upvotes: 3

Maurizio In denmark
Maurizio In denmark

Reputation: 4284

Try setting the new value for the MaxNameTableCharCount property programmatically:

Binding binding = endpoint.Binding;

XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();
myReaderQuotas.MaxStringContentLength = something;
myReaderQuotas.MaxArrayLength = something;
myReaderQuotas.MaxBytesPerRead = something;
myReaderQuotas.MaxDepth = something;
myReaderQuotas.MaxNameTableCharCount = something;

binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null);

Note: you have to set it BEFORE the client proxy and/or service host are created. Once created, they can't be changed.

Upvotes: 0

The other other Alan
The other other Alan

Reputation: 1918

I don't suppose its practical to split up the operations into multiple contracts? Mind if I ask how many service operations we're talking about?

Have you tried the solutions in this post? http://social.msdn.microsoft.com/Forums/vstudio/en-US/17592561-c470-452a-a52c-2a5a2839582c/metadataexchangeclient-and-nametable-character-count-quota

Among other suggestions are using the Discovery protocol to read metadata, which does not have any reader quotas: http://msdn2.microsoft.com/en-us/library/system.web.services.discovery.discoveryclientprotocol.aspx

The solution at the bottom suggests you change the default reader quotas in code before starting the service. I believe this would have to be done in a custom ServiceHost factory. Please let me know if you would assistance with that.

Hope this helps.

Upvotes: 1

Chris
Chris

Reputation: 2481

This should help: http://geekswithblogs.net/claraoscura/archive/2007/08/20/114806.aspx appears that the solution is to create a config file for svcutil and place it in the same folder as it.

Upvotes: 0

Related Questions