0

我们的应用程序通过 basicHttpBinding 使用 WCF 上的许多 Web 服务。XML 消息通常非常大 (>2mb)。

在运行时,我们间歇性地收到一个似乎与 ReaderQuotas 相关的反序列化错误,该错误已设置为 Int32.MaxValue。

堆栈的头部是(抱歉,必须从提供的图像中手动输入):

System.ServiceModel.Dispatcher.NetDispatcherFaultException: The formatter threw an 
exception while trying to deserializat the message: There was an error while trying to
deserialize parameter [the namespace]. 

The InnerException message was 'There was an error deserializing the object of type 
[a type]. The maximum array length quota (5) or the maximum items in object graph 
quota has been exceeded while reading XML data. These quotas may be increased by
changing the MaxArrayLength property on XmlDictionaryReaderQuotas or the 
MaxItemsInObjectGraph setting. Line 1, position 3645191.

客户端配置:

<client>
      <endpoint address="http://someUri/someSvc" binding="basicHttpBinding" bindingConfiguration="SomeSvcBindingConfiguration" contract="SomeSvc" name="SomeSvc" behaviorConfiguration="ClientObjectBehavior" />
</client>

<behaviors>
      <endpointBehaviors>
        <behavior name="ClientObjectBehavior">
          <dataContractSerializer maxItemsInObjectGraph="131072"  />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="SomeSvcBindingConfiguration" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:00:15" sendTimeout="00:00:15" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="10485760" maxBufferPoolSize="524288" maxReceivedMessageSize="10485760" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="false">
          <readerQuotas maxDepth="2147483647"
                              maxStringContentLength="2147483647"
                              maxArrayLength="2147483647"
                              maxBytesPerRead="2147483647"
                              maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>

...

任何人都可以提出为什么这个异常可能仍然发生?

没有工具可以将绑定从 basicHttpBinding 更改,除非它是自定义设置的某种等效组合。

4

1 回答 1

0

The number hinted in the exception message - the "(5)" - is actually the running value for the MaxArrayLength setting. Why it is five in this case, I cannot determine without further details.

However, having only a maximum of 131072 objects in the graph might be too small - the maxItemsInObjectGraph="131072" setting. Since the error happens at position 3645191 of the xml content, I'd assume that there might be more objects inside that xml than 131072.

于 2013-03-13T01:47:17.953 回答