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

来源:互联网 发布:在淘宝退货卖家拒收 编辑:程序博客网 时间:2024/05/21 14:47

原始异常:

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:CheckedResult. The InnerException message was 'There was an error deserializing the object of type SDTool.VFRService.CheckedResponse. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 18538.'.  Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type SDTool.IVFRService.CheckedResponse. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 18538. ---> System.Xml.XmlException: The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 18538

原因分析:

在WCF中已经配置如下配置:

<bindings>      <basicHttpBinding>        <binding name="BasicHttpBinding_IReseiverService" receiveTimeout="00:10:00" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="1048576000" maxReceivedMessageSize="1048576000">          <readerQuotas maxDepth="640" maxStringContentLength="1048576000" maxArrayLength="1048576000" maxBytesPerRead="1048576000" maxNameTableCharCount="1048576000"/>          <security mode="None">            <message clientCredentialType="UserName"/>          </security>        </binding>      </basicHttpBinding>    </bindings>
在客户端的配置如下:

<binding name="BasicHttpBinding_IReseiverService"  maxReceivedMessageSize="104857600">        </binding>
在windows10系统中运行,客户端能正常访问,但是在windows7系统中就会出现上面的异常信息,通过尝试,需在客户端配置与服务端一样的配置。结果如下:

<binding name="BasicHttpBinding_IReseiverService"  maxReceivedMessageSize="104857600">          <readerQuotas maxDepth="640" maxStringContentLength="1048576000" maxArrayLength="1048576000" maxBytesPerRead="1048576000" maxNameTableCharCount="1048576000"/>        </binding>

在交给客户使用后不久又出现以下问题:

The formatter threw an exception while trying to deseriabize the message:There was an error while trying to deserialize parameter http://tempuri.org/:QueryRecordResult.The InnerException message was'Maxinum number of items that can be serialized or deserialized in an object graph is '65536'.Change the object praph or increase the MaxItemInObjectGraph quota.'.Please see InnerException for more details.

在客户端配置文件节点system.serviceModel增加一个名称为NewBehavior的节点

<behaviors>      <endpointBehaviors>        <behavior name="NewBehavior">          <dataContractSerializer maxItemsInObjectGraph="65536000" />        </behavior>      </endpointBehaviors>    </behaviors>

同时在client节点的endpoint节点内怎加如下配置,跟上面内容关联。
behaviorConfiguration="NewBehavior",配置结果如下

<endpoint address="http://127.0.0.1:9371/ReseiverService.svc" behaviorConfiguration="NewBehavior"        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IReseiverService"        contract="IDCardService.IReseiverService" name="BasicHttpBinding_IReseiverService" />

阅读全文
0 0