我有一个在特定端点连接到 web 服务的 3rd 方库。对于某些服务,我得到以下异常:
Message=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. Line 1, position 1339.
解决办法是,增加ReaderQuoata。WCF 通过配置文件建议这一点。
我的 app.config 现在看起来像:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding>
<readerQuotas maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
当我现在创建一个新的 WsHttpBinding 时,它的值仍然是默认值 16384。
class Program
{
static void Main(string[] args)
{
WSHttpBinding x = new WSHttpBinding();
Console.WriteLine(x.ReaderQuotas.MaxNameTableCharCount); //prints 16384
}
}
我错过了什么?