WCF:读取XML数据时已超出最大字符串内容长度配额(8192)

时间:2015-03-26 21:15:14

标签: .net web-services wcf web-config

在浏览了互联网和StackOverflow之后,我还没有找到一个有效的解决方案。当我试图读取我得到的响应时,内部异常是:

  

读取XML数据时已超出最大字符串内容长度配额(8192)。通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象的MaxStringContentLength属性,可以增加此配额。

我是一个联系服务器的客户端,我收到的回复是,在查看响应后,远远大于8192限制。我已将我的客户端配置更新到最高级别,但它没有帮助。我不知道在哪里更新限制,所以任何帮助都会受到赞赏:

客户端配置:

<configuration>
  <system.serviceModel>
    <client>
      <endpoint name="CaqhCore_EndpointWithCertificates" address="https://MyEndPoint" behaviorConfiguration="Cbc_BehaviorWithCertificateSigning" binding="customBinding" bindingConfiguration="Cbc_BindingWithCertificates" contract="CORETransactions">
        <identity>
          <certificateReference findValue="1h 1h 1h 1h 1h 1h 1h 1h 1h 1h" x509FindType="FindByThumbprint" />
        </identity>
      </endpoint>
    </client>
    <bindings>
      <customBinding>
        <binding name="Cbc_BindingWithCertificates" maxReceivedMessageSize="2147483647">
          <security enableUnsecuredResponse="false" allowSerializedSigningTokenOnReply="true" authenticationMode="MutualCertificate" requireDerivedKeys="false" includeTimestamp="true" messageProtectionOrder="SignBeforeEncrypt" messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
            <issuedTokenParameters keyType="AsymmetricKey" />
            <secureConversationBootstrap>
              <issuedTokenParameters keyType="AsymmetricKey" />
            </secureConversationBootstrap>
          </security>
          <textMessageEncoding messageVersion="Soap12WSAddressingAugust2004" writeEncoding="utf-8">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </textMessageEncoding>
          <httpsTransport />
        </binding>
      </customBinding>
    </bindings>
  </system.serviceModel>
</configuration>

请注意,由于隐私问题,我已从配置中删除了我认为不相关的信息,但如果您需要查看行为或其他元素等其他内容,请与我们联系。

1 个答案:

答案 0 :(得分:0)

我找到了答案。问题是我正在使用的代码(不是由我编写)的代码包含对象: XmlDictionaryReaderQuotas 已注释掉,这意味着它无法从配置文件中读取readerQuotas节点,因此使用默认值。

相关问题