WCF - 读取XML数据时已超出最大名称表字符计数配额(16384)

Jan*_*ana 9 c# wcf svcutil.exe wcf-wshttpbinding

我有一个使用wsHttpBinding的WCF服务.服务器配置如下:

<bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
              algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
Run Code Online (Sandbox Code Playgroud)

在客户端,我包括WCF服务的服务参考.如果我的功能有限,在我的IService中说90操作合同但是如果再添加一个OperationContract而不是我无法更新服务引用,我也能添加该服务引用.在这个文章它提到,在这些配置文件仍改变这些配置文件(即devenv.exe.config,WcfTestClient.exe.config和SvcUtil.exe.config),它会工作,但即使包括那些绑定的错误弹出说

下载' http://10.0.3.112/MyService/Service1.svc/mex '时出错.请求失败,HTTP状态为400:错误请求.元数据包含无法解析的引用:' http : //10.0.3.112/MyService/Service1.svc/mex '.XML文档中存在错误(1,89549).读取XML数据时已超出最大名称字符集计数配额(16384).nametable是用于存储XML处理期间遇到的字符串的数据结构 - 具有非重复元素名称,属性名称和属性值的长XML文档可能会触发此配额.通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象上的MaxNameTableCharCount属性,可以增加此配额.第1行,位置89549.如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用.

不知道怎么解决这个????

Fab*_*ano 11

请尝试以下方法:

在devenv.exe所在的Visual Studio的安装目录中(例如C:\ Program Files\Microsoft Visual Studio 9.0\Common7\IDE),将此部分添加到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>
Run Code Online (Sandbox Code Playgroud)

在您的WCF服务的app.config中添加相同的绑定:

<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>
Run Code Online (Sandbox Code Playgroud)

请注意,两个文件中绑定标记的name属性必须匹配(例如,largeServiceBinding)

最后将以下mex端点添加到服务标签中:

 <endpoint address="mex" binding="customBinding" contract="IMetadataExchange" bindingName="testBinding" bindingConfiguration="largeServiceBinding" name="http"/>
Run Code Online (Sandbox Code Playgroud)

这可能看起来像这样:

 <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>
Run Code Online (Sandbox Code Playgroud)


Sim*_*imY 5

我知道它已经有一段时间了,但我遇到了同样的问题,并在codeproject中找到了其他(更简单的)解决方案

在给定的解决方案中,值在代码中而不是.config文件中设置.

        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);
Run Code Online (Sandbox Code Playgroud)

但是,我更改了.config文件(在<binding><readerQuotas>部分中)的相关值中的值并解决了问题(而不是添加自定义绑定):

                <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>
Run Code Online (Sandbox Code Playgroud)

我希望这会有所帮助:)