【问题标题】:WCF client ReaderQuota error despite having set high limits尽管设置了上限,但 WCF 客户端 ReaderQuota 错误
【发布时间】:2013-02-28 18:07:38
【问题描述】:

我们的应用通过 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 更改,除非它是自定义设置的某种等效组合。

【问题讨论】:

    标签: c# .net wcf c#-4.0 wcf-binding


    【解决方案1】:

    异常消息中提示的数字“(5)”实际上是 MaxArrayLength 设置的运行值。为什么在这种情况下是 5,没有更多细节我无法确定。

    但是,图表中最多只有 131072 个对象可能太小 - maxItemsInObjectGraph="131072" 设置。由于错误发生在 xml 内容的位置 3645191,我假设该 xml 中的对象可能比 131072 更多。

    【讨论】:

    • 令人讨厌的是,在我进行此更改之前,该问题刚刚消失并且不再可重现。不过你确实提出了一个很好的观点,所以我要给你加分
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 2021-02-08
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 2020-10-01
    • 1970-01-01
    相关资源
    最近更新 更多