jaircazarin
jaircazarin

Reputation: 75

Maximum nametable char count quota

I have a WCF Service (SOAP based) that started hitting the following exception when calling some of the web methods:

System.Xml.XmlException: 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 4221. at System.Xml.XmlExceptionHelper.ThrowXmlException

While we fixed this already by increasing the quotas in the service and client configuration, I see no differences in the message response before we started hitting the issue and after applying the quota increase.

My questions are:

  1. How does the name table really works? And what are the implications of having a name table with the maximum value?

  2. Is there something that could potentially explain why we starting to hit this exception without changing the service and test cases? We added a couple of methods though but I'm not sure if that's a good explanation given those web methods were not being called.

  3. Any recommendations on debugging name table and see what's causing to hit the overflow?

Thanks

Upvotes: 1

Views: 993

Answers (2)

Dror Harari
Dror Harari

Reputation: 3307

We added a couple of methods though but I'm not sure if that's a good explanation given those web methods were not being called.

I have seen a similar behavior following a change in our WCF application where we just added a few attributes to one of the XML messages in our protocol. Turned out that those new attributes were little long (~25 plus character each) and by decreasing their length the problem disappeared.

Given that the problem appeared with our open-session message which is tiny and that the error stack showed the auto-generated XML serializer I conclude that as an optimization step, the auto-generated XML serializer tries to pre-populate the XML parser's nametable on first use without changing its default max size of 16Kb to match the actual size according to the 'compiled' XML schema. That explains why a tiny XML request blows when the WCF stack tries to deserialize it.

Adding this line solved the above problem:

webHttpBinding.ReaderQuotas.MaxNameTableCharCount = 32768;

Upvotes: 1

Yaron Naveh
Yaron Naveh

Reputation: 24426

  1. when parsing xml, each element/attribute name in the message is put in some table, so they can be efficiently reused. the reason for this quota is to avoid dos (denial of service attack), e.g. someone sends very large messages to consume all your server processing code. if you do not expect this to happen you can use the max.

  2. maybe you changed wcf version so the defaults have changed. also maybe something causes the client to do serialization differently (e.g. more attributes) so it sent something more verbose.

  3. just increase the quota and forget about it.. you don't want to debug this

Upvotes: 1

Related Questions