解决WCF The maximum nametable character count quota (16384) has been exceeded while reading XML data问题

来源:互联网 发布:tsc标签设计软件 编辑:程序博客网 时间:2024/05/22 02:11
今天将客户端程序引用之前创建的一个方法相当多的services的时候碰到如下一个错误,
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:9997/DataService/mex'.There is an error in the XML document.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.If the service is defined in the current solution, try building the solution and adding the service reference again.


当前的endpoint配置
<service behaviorConfiguration="MyBehavior" name="XXX.XXXX.DataService">       <endpoint address="" binding="netTcpBinding" name="NetTcpEndPoint" contract="XXX.XXXX.XXXXXXX.XXXX.XXXXXXXXXXXXXX.IDataService"/>       <endpoint address="mex" binding="mexTcpBinding" name="NetTcpMetadataPoint" contract="IMetadataExchange"/>       <host>        <baseAddresses>         <add baseAddress="net.tcp://localhost:9997/DataService/"/>        </baseAddresses>       </host>      </service>

解决办法:
1.在service的app.config的<system.serviceModel>节电下创建一个新的bindings, 使用netTcpBinding来代替mexTcpBinding:
<bindings>      <netTcpBinding>        <binding name="GenericBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>          <security mode="None"/>        </binding>      </netTcpBinding></bindings>

2.将之前的endpoint设置改成
<service behaviorConfiguration="MyBehavior" name="XXX.XXXX.DataService">       <endpoint address="" binding="netTcpBinding" name="NetTcpEndPoint" bindingConfiguration="GenericBinding" contract="XXX.XXXX.XXXXXXX.XXXX.XXXXXXXXXXXXXX.IDataService"/>       <endpoint address="mex" binding="netTcpBinding" name="NetTcpMetadataPoint" bindingConfiguration="GenericBinding" contract="IMetadataExchange"/>       <host>        <baseAddresses>         <add baseAddress="net.tcp://localhost:9997/DataService/"/>        </baseAddresses>       </host>      </service>

3.修改Client端的app.config 或者在"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE" 下的devenv.exe.config(修改这个的话需要重启VS)中添加.
添加
<system.serviceModel>    <bindings>      <netTcpBinding>        <binding name="GenericBinding" maxBufferPoolSize="2147483647"          maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />          <security mode="None" />        </binding>      </netTcpBinding>    </bindings>    <client>      <endpoint binding="netTcpBinding" bindingConfiguration="GenericBinding"        contract="IMetadataExchange" name="net.tcp" />    </client>  </system.serviceModel>
  

4.之后再重新Add Service References就正常了.

我的原文连接 http://www.markgoo.com/?p=73

原创粉丝点击