-1

I´m having a 3rd party library that connects to webservice at specific endpoints. With some services, i get the following exception:

Message=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. Line 1, position 1339.

The solution is, to increase the ReaderQuoata. WCF suggests this via config files.

My app.config now looks like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    </startup>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding>
          <readerQuotas maxNameTableCharCount="2147483647" />
        </binding>
      </wsHttpBinding>
    </bindings>   
  </system.serviceModel>
</configuration>

When i now create a new WsHttpBinding, the value of it is still the default value of 16384.

    class Program
    {
        static void Main(string[] args)
        {
            WSHttpBinding x = new WSHttpBinding();
            Console.WriteLine(x.ReaderQuotas.MaxNameTableCharCount); //prints 16384 
        }
    }

What am i missing?

kamahl
  • 931
  • 1
  • 8
  • 20
  • did you try this? http://stackoverflow.com/questions/2765598/wcf-the-maximum-nametable-character-count-quota-16384-has-been-exceeded-whil – Ahmed ilyas Oct 31 '15 at 19:48
  • i checked on it ... but didn't get it to work so i tried simlifying it with a few lines of code and using app.config – kamahl Oct 31 '15 at 21:37

2 Answers2

1

WSHttpBinding x = new WSHttpBinding(); creates a new instance of WSHttpBinding with the framework default values. Even though you have a default binding configuration defined in the configuration file, it is not being used by your code (See WSHttpBinding.cs for the source code). In other words, calling the parameterless constructor of WSHttpBinding does not apply the default binding from any associated config files, at least that I could see.

You have a couple of options here. First, give a name for the binding configuration in your config file and reference that. Second, assign the values to the XmlDictionaryReaderQuotas when you create the binding programatically.

Option 1

<bindings>
  <wsHttpBinding>
    <binding name="MyBinding">
      <readerQuotas maxNameTableCharCount="2147483647" />
    </binding>
  </wsHttpBinding>
</bindings>

WSHttpBinding x = new WSHttpBinding("MyBinding");

Option 2

WSHttpBinding x = new WSHttpBinding();
x.ReaderQuotas rq = new XmlDictionaryReaderQuotas();
rq.MaxNameTableCharCount = Int32.MaxValue;
Tim
  • 28,212
  • 8
  • 63
  • 76
  • Ohhh .... the problem is, the code is like this in the 3rd Party DLL that we use (acutally MS CRM 2013 SDK). With reflector, i found that the binding there is instantiatet like: return new WSHttpBinding(SecurityMode.None, false) { Name = "MetadataExchangeHttpBinding", Namespace = "http://schemas.microsoft.com/ws/2005/02/mex/bindings" }; Is there a way to change this binding? I suppose not as Name is not passed as an argumentbut is set in { }. Thank you very much in advance! – kamahl Nov 03 '15 at 11:36
  • @kamahl - There's no easy way to change the binding in the 3rd Party DLL, unfortunately. If the error is being received on the client side (i.e., when the client tries to deserialize the response), you can change the quotas on the client's definition of the binding, but if you're receiving this error from the service, you're in a tougher spot. You could try reducing the amount of information you expect back from the service, but that could quickly turn into a long and painful guessing game. – Tim Nov 05 '15 at 01:05
  • hi i´m on the client side with the 3rd party dll, and we have no specific binding but the dll discovers the connection at runtime and uses the system.servicemodel.metadataclient to get the metadata. this one breaks. – kamahl Nov 05 '15 at 14:56
0

Did you try this link https://social.msdn.microsoft.com/Forums/vstudio/en-US/17592561-c470-452a-a52c-2a5a2839582c/metadataexchangeclient-and-nametable-character-count-quota?forum=wcf

this is a bug in our code (the binding you pass is ignored for HTTP-GET). There are a few workarounds

can you see if any of them will work for you?

DeanOC
  • 7,142
  • 6
  • 42
  • 56
M_1100
  • 67
  • 1
  • 1
  • 7
  • hi. Thanks for the link! it's new information to me. It looks like this bug is fixxed, but i´ll catch up with the reflection idea! – kamahl Nov 03 '15 at 11:43