Geeks With Blogs
Clara's Notes on Technology Notes to me and the world

It has been a while since I last posted, but I haven't stopped working :) I am currently on a project involving WPF and WCF. While I am not a big fan of WPF, but I quite like WCF.

During the development of our project we run into a very annoying problem with WCF. After some help from Microsoft, we found a solution at last.

The problem is very easy to describe. On the one side, we have a WCF service running. On the other side, we have a client with a reference with to this service. Now and then, we need to update the service reference (because the service includes new features, for example). You can do this with svcutil or by right clicking on the reference in VisualStudio and choosing the "Update Service Reference" option.

One day, when updating the reference (with svcutil) we got this message:

Error: Cannot obtain Metadata from http://localhost:8000/businessservice/service/mex

The maximum nametable character count quota (16384) has been exceeded whilereading 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.

After several Google searches, I thought this could be solved by increasing the reader quotas parameters for the metadata exchange binding. This implied some minor changes in the service config file since the the mexBinding configuration section does not provide any properties: you have to use a wsHttpBinding without any security. This is explained here and Michele Leroux Bustamante (an expert on WCF) even provides a couple of samples (config-based sample here, and code-based sample here).

However, this did not help at all. Even setting the reader quotas to the maximum possible values made no difference at all. In the end, Microsoft told me what was wrong: the message refers to the svcutil reader quotas not the service ones! Svcutil has a limit on how much metadata it can read. This limit can be changed with a config file.

The solution is to create a config file for svcutil (see below) and place it in the same folder as the tool. Next time you run svcutil, the config file values will be taken into account.

 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="MyBinding">
                    <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="MyBinding"
                contract="IMetadataExchange"
                name="http" />
        </client>
    </system.serviceModel>
</configuration>

 

The MSDN WCF samples contain an example of creating this config file, although the main issue is a different one (how to configure svcutil to fetch metadata from a custom endpoint), so it wasn't so obvious to make the connection.

 

Technorati tags: ,
Posted on Monday, August 20, 2007 6:36 PM | Back to top


Comments on this post: The maximum nametable character count quota (16384) has been exceeded

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Thanks, you saved my a$$ today!!!
Left by Guy Barrette on Nov 20, 2008 10:29 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
So you HAVE to use an HTTP binding?? You can't make this work with NetTCPBinding??
Left by Joe Krueger on Dec 15, 2008 10:12 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Hi, really good post, I spent with this problem 2 days until finally I got it, another solution is to update the config for devenv.
Left by Diadiora Alexandru on Jan 14, 2009 9:03 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
This will not solve the issue on NET.TCP binding.
I just tried it
Left by Mirzet on Apr 09, 2009 7:10 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Thanks a lot!!
Left by Raul Pereda on Jul 27, 2009 5:10 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
I have figured out how to exchange the Net.tcp.

You have to put in BasicHttp binding, together with Net.TCP, so that Mex can use Http for data exchange, but also able to find out the end point for Net.TCP.

You then remove the endpoint for BasicHttp on both server and client's config.
Left by Ken Han on Aug 05, 2009 8:16 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
This is the gift that keeps on giving. In one minute you've saved me from a multi-day ordeal. Deeply grateful!
Left by Evan Stein on Aug 06, 2009 5:12 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
I ran into this problem when my WCF service reached a large size.
I could no longer right click on the service in Visual Studio and select Update service reference.

I also could not run svcutil.exe without an error when my WCF service was large.
When I commented out some of the functions to get the size smaller, everything would work, but when I added even one function after that point, it would fail. No matter what the function was.

I found out which files needed to be changed by using process monitor while doing various operations.

To fix these problems I had to do 5 things:

1) Replace the svcutil.exe.config file with:
My file was located here: SvcUtil.exe.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<client>
<endpoint name="net.tcp" binding="netTcpBinding" bindingConfiguration="GenericBinding"
contract="IMetadataExchange" />
<endpoint name="http" binding="wsHttpBinding" bindingConfiguration="SecureBinding" contract="IMetadataExchange" />
</client>
<bindings>
<netTcpBinding>
<binding name="GenericBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</netTcpBinding>
<wsHttpBinding>
<binding name="SecureBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Message">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>


2) Add the client endpoints and the <bindings> element to your machine.config.
My file was located here: C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

3) Add the whole <System.ServiceModel> inside your devenv.exe.config
My file was located here: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.config

4) Modify the endpoint and bindings of my client app. (myapp.exe.config)

5) Modify the endpoints and bindings of my WCF service. (mywcfservice.exe.config)
Left by Brian R. Bondy on Nov 20, 2009 10:51 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
WOW... I spent so much time trying to fix this.
Gave up then it snuck up on me again.
I was so happy when your solution worked. Fabulous!!
Left by Willhunting on Jan 20, 2010 2:51 AM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Brian, thank you so much for your solution! Really made my day, thanks!
Left by Mike S. on Feb 22, 2010 3:58 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Thanks so much for your solution! It works perfectly! By the way, this issue has not yet been addressed in VS2010, poor...
Left by Eddie Chu on Apr 22, 2010 8:19 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Diadiora, thank you very much, this solution worked very and saved me much frustration!
Left by Zac Horn on Apr 28, 2010 1:57 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Thank you for taking time to blog this. This has saved my day.
Left by krish on Jul 06, 2010 8:54 AM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
In Machine.Config, 1'st write in XML
<bindings>
<netTcpBinding>
<binding name="GenericBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>

then

<client>
<endpoint name="net.tcp" binding="netTcpBinding" bindingConfiguration="GenericBinding" contract="IMetadataExchange" />
<metadata>
<policyImporters>
<extension type="System.ServiceModel.Channels.ContextBindingElementImporter, system.workflowservices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
</policyImporters>
<wsdlImporters>
<extension type="System.ServiceModel.Channels.ContextBindingElementImporter, system.workflowservices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
</wsdlImporters>
</metadata>
</client>

under
<system.serviceModel> tag,


now i am cooL, and its working really GooD in my case :)

Thanks for publishing such helping stuff.
Left by Muhammad Niaz on Mar 31, 2011 9:44 AM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Thanks a lot for this. I spent more than 4 hours before i stumbled upon your link, Muhammad Niaz's svcutil.exe.config was a life saver.
Left by Senthil on Apr 14, 2011 9:24 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
Your name shall be etched in digital stone for all time.
Left by WhiskeyDelta on Jun 14, 2011 5:00 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
I've modified a lot of svcutil.exe generated cs code, then met this issue.
is there any workaround without re-run svcutil.exe using the new config file?
Left by charles on Jun 29, 2011 6:39 AM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
you have to change maxReceivedMessageSize only really it seems. For net.tcp this is enough:

<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>

<binding name="texMex" maxReceivedMessageSize="1024000"><!-- increase this one-->
<readerQuotas maxNameTableCharCount="163840" /><!-- never touch this-->
<security mode="None" />
</binding>
....
<client>
<endpoint binding="netTcpBinding" bindingConfiguration="texMex"
contract="IMetadataExchange" name="net.tcp" />

Left by Stian on Sep 22, 2011 4:47 PM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
I just got this done by change the value of maxNameTableCharCount to 2147483647 in my app.config file. I did not do any change in svcutil.exe.config or machine.config.
Left by Prasoon on May 17, 2012 9:07 AM

# re: The maximum nametable character count quota (16384) has been exceeded
Requesting Gravatar...
The solution provided by Prasoon worked for me too. Thanks!
Left by MaroWilanow on Sep 13, 2012 5:02 PM

Your comment:
 (will show your gravatar)


Copyright © Clara Oscura | Powered by: GeeksWithBlogs.net | Join free