WCF - The maximum nametable character count quota (16384) has been exceeded while reading XML data

前端 未结 4 1213

I\'m having a WCF Service that uses wsHttpBinding. The server configuration is as follows :


      &l         


        
相关标签:
4条回答
  • 2020-12-17 22:00

    in your app.config or dll.config on the the client add:

    <configuration>
    <system.serviceModel>
    <bindings>
    <netTcpBinding>
    <binding name="myMex" maxReceivedMessageSize="1024000"> <!-- modify this to avoid stupid error -->
    <readerQuotas maxNameTableCharCount="163840" /> <!-- DO NOT touch this one -->
    <security mode="None" />
    </binding>
    </netTcpBinding>
    </bindings>
    
    ...
    
    <client>
    <endpoint binding="netTcpBinding" bindingConfiguration="myMex"
    contract="IMetadataExchange" name="net.tcp" />
    
    ...
    
            </client>
        </system.serviceModel>
    </configuration>
    

    And there you go! This is one of the really annoying things with WCF and as often google just yields you alot of bs. Wasted tons of time with this.

    0 讨论(0)
  • 2020-12-17 22:06

    Try the following:

    In the installation directory of your Visual Studio where devenv.exe is located (e.g. C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE) add this section to the devenv.exe.cofig

    <system.serviceModel>
    <client>
      <endpoint binding="customBinding" bindingConfiguration="largeServiceBinding" contract="IMetadataExchange" name="http" />
    </client>
    
    <bindings>
      <customBinding>
        <!-- NOTE: The binding name must be the same as specified in the config file of the wcf service -->
        <binding name="largeServiceBinding" >
          <textMessageEncoding>
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </textMessageEncoding>
    
          <httpTransport transferMode="Buffered" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
        </binding>
    
      </customBinding>
    </bindings>
    </system.serviceModel>
    

    in the app.config of your WCF-service add the same binding:

    <bindings>
      <customBinding >
        <!-- NOTE: The binding name must be the same as specified in the devenv.exe.config file located ..\Common7\IDE folder of the VS installation directory -->
        <binding name="largeServiceBinding" >
          <textMessageEncoding>
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"
              maxNameTableCharCount="2147483647" />
          </textMessageEncoding>
          <httpTransport transferMode="Buffered" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
        </binding>
      </customBinding>
    </bindings>
    

    Note that the name attribute of the binding tags from the two files must match (e.g. largeServiceBinding)

    Finally add the following mex endpoint into your service tag:

     <endpoint address="mex" binding="customBinding" contract="IMetadataExchange" bindingName="testBinding" bindingConfiguration="largeServiceBinding" name="http"/>
    

    this may look like this:

     <services>
      <service behaviorConfiguration="MyServiceBehavior"
        name="MyService.MyService">
        <endpoint address="" binding="wsHttpBinding" contract="MyService.IMyService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="customBinding" contract="IMetadataExchange" bindingName="testBinding" bindingConfiguration="largeServiceBinding" name="http"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/MyService/MyService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    
    0 讨论(0)
  • 2020-12-17 22:09

    One thing to recognize is that 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 and place it in the same folder as the tool. Next time you run svcutil, the config file values will be taken into account.

    http://geekswithblogs.net/claraoscura/archive/2007/08/20/114806.aspx

    0 讨论(0)
  • 2020-12-17 22:22

    I know it has been a while, but I got the same problem and found other (simpler) solution in codeproject

    In the solution given there the values are set in the code rather than the .config file.

            BasicHttpBinding binding = new BasicHttpBinding();
            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
            binding.MaxReceivedMessageSize = 50000000;
            binding.ReaderQuotas.MaxArrayLength = 50000000;
            binding.ReaderQuotas.MaxStringContentLength = 50000000;
            binding.ReaderQuotas.MaxNameTableCharCount = 50000000;
            EndpointAddress endpoint = new EndpointAddress(new Uri("https://server/EWS/Exchange.asmx"));
            ExchangeServicePortTypeClient ews = new ExchangeServicePortTypeClient(binding, endpoint);
    

    However, I changed the values in the relevant values in the .config file ( in both the <binding> and the <readerQuotas> sections) and solved the problem (rather than adding custom bindings):

                    <binding name="ITransactionProcessor" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="50000000" maxBufferPoolSize="524288" maxReceivedMessageSize="50000000"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="50000000" maxArrayLength="50000000"
                            maxBytesPerRead="4096" maxNameTableCharCount="50000000" />
                        <security mode="TransportWithMessageCredential">
                            <transport clientCredentialType="None" proxyCredentialType="None" 
                                realm="" />
                            <message clientCredentialType="UserName" algorithmSuite="Default" />
                        </security>
                    </binding>
    

    I hope this will help somebody :)

    0 讨论(0)
提交回复
热议问题