WCF服务:已超出最大数组长度限制(16384)

27
我有一个wsf服务和一个客户端应用程序。在试图通信客户端和服务时,我得到了以下消息:
"格式化程序在尝试反序列化消息时引发了异常:尝试反序列化参数http://tempuri.org/:blob时出错。 InnerException消息为'There was an error deserializing the object of type FileBlob. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 25931.'。请参见InnerException以获取更多详细信息。"
我有自定义绑定元素,但它不允许我插入“readerQuotas”部分。在客户端和服务配置文件中,我都有以下绑定元素:
<customBinding>
  <binding name="LicenseServiceBinding"
                closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
      <security authenticationMode="UserNameOverTransport">
          <localClientSettings maxClockSkew="00:07:00" />
          <localServiceSettings maxClockSkew="00:07:00" />
      </security>
      <windowsStreamSecurity />
      <httpsTransport maxReceivedMessageSize="2147483646"/>          
  </binding>
</customBinding>

非常感谢您的帮助:)

2个回答

46

实际上,我通过在textMessageEncoding部分添加readerQuotas来解决了这个问题。感谢你的帮助。

<textMessageEncoding messageVersion="Soap11">
          <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="5242880"/>
</textMessageEncoding>

7
这也适用于其他消息编码,例如 <binaryMessageEncoding>。 - Aaginor

18

你应该能够在 <binding> 元素内添加一个 <readerQuotas> 元素:

<customBinding> 
  <binding name="LicenseServiceBinding" 
                closeTimeout="00:01:00" openTimeout="00:01:00" 
                receiveTimeout="00:10:00" sendTimeout="00:01:00"> 
      <security authenticationMode="UserNameOverTransport"> 
          <localClientSettings maxClockSkew="00:07:00" /> 
          <localServiceSettings maxClockSkew="00:07:00" /> 
      </security> 
      <readerQuotas maxArrayLength="32768" />
      <windowsStreamSecurity /> 
      <httpsTransport maxReceivedMessageSize="2147483646"/>           
  </binding> 
</customBinding> 

您提到它“不允许我插入”。您收到了什么错误消息?


9
似乎对于自定义绑定,readerQuotas 必须嵌套在你设置的任何 MessageEncoding(如 textMessageEncoding、binaryMessageEncoding 等)中。编码是 <binding> 的子元素。 - Aaginor

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接