zoukankan      html  css  js  c++  java
  • WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while reading XML data错误

    WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while reading XML data错误

    在服务端中定义接口太多时,在客户端的服务引用时,报错误:

     元数据包含无法解析的引用:“net.tcp://localhost:8081/BaseData/mex”。    XML 文档中有错误。    读取 XML 数据时,超出最大名称表字符计数配额 (16384)。名称表是用于存储在处理 XML 时所遇到的字符串的数据结构 - 具有非重复元素、属性名称和属性值的长 XML 文档可能会触发此配额。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的  MaxNameTableCharCount 属性,可增加此配额。

    解决方法:

    服务端配置文件:

    <system.serviceModel>
        <services>
          <!--基础数据服务-->
          <service name="PmsWcfServer.PmsWcfBaseData" behaviorConfiguration="WcfBaseData">
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://127.0.0.1:8081"/>
              </baseAddresses>
            </host>
            <endpoint address="" binding="netTcpBinding"  contract="PmsWcfServer.IPmsWcfBaseData" bindingConfiguration="BindBaseData"/>
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
     
        <behaviors>
          <serviceBehaviors>
            <behavior name="WcfBaseData">
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <serviceMetadata httpGetEnabled="false"/>
              <serviceCredentials>
                <serviceCertificate x509FindType="FindBySubjectName" findValue="PmsWcfServer" storeLocation="LocalMachine"/>
                <userNameAuthentication userNamePasswordValidationMode="Custom"  customUserNamePasswordValidatorType="PmsWcfServer.CheckUserNamePass,PmsWcfServer"/>
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
          
          <endpointBehaviors>
            <behavior name="BindBaseData">
              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        
        <bindings>
          <netTcpBinding>
            <binding name="BindBaseData" maxReceivedMessageSize="2147483647">
              <security mode="Message">
                <message clientCredentialType="UserName"/>
              </security>

    <!--注意:红色字体,这里必须要修改maxNameTableCharCount值,增大配额--> 

              <readerQuotas maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxDepth="32000"/>
            </binding>
          </netTcpBinding>
        </bindings>
      </system.serviceModel>

        只是修改以上配置文件,客户端依然后引用不成功,还需要修改:C:Program FilesMicrosoft Visual Studio 10.0Common7IDEdevenv.exe.Config文件,在文件后面增加以下节:

       <system.serviceModel>  
        <bindings>  
          <netTcpBinding>  
            <binding name="BindSystemmaxBufferPoolSize="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="BindSystem"  
            contract="IMetadataExchange" name="net.tcp" />  
        </client>  

      </system.serviceModel> 

    重启VS,后再次引用成功! 

    转自http://www.cnblogs.com/y740504/archive/2012/01/16/2323235.html

  • 相关阅读:
    [C++] 习题 2.18 倒序查找字串
    [C++] 二叉树计算文件单词数
    [C++] 例题 2.7.1 用栈实现简易计算器
    [C++] 非递归实现前中后序遍历二叉树
    [C++] 习题 2.15 实现简单环形队列
    数据结构、算法及应用
    [C++] 习题 2.14 用队列实现桶排序
    svn add 所有文件的命令
    解决Error opening terminal: xterm.的错误
    linux下删除项目中所有.svn的命令
  • 原文地址:https://www.cnblogs.com/lucky_hu/p/3375261.html
Copyright © 2011-2022 走看看