天天看點

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"/>

      </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 Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.Config檔案,在檔案後面增加以下節:

   <system.serviceModel>  

    <bindings>  

      <netTcpBinding>  

        <binding name="BindSystem" 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="BindSystem"  

        contract="IMetadataExchange" name="net.tcp" />  

    </client>  

  </system.serviceModel> 

重新開機VS,後再次引用成功!