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

原始异常:

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>
<bindingname="BasicHttpBinding_IReseiverService"receiveTimeout="00:10:00"closeTimeout="00:05:00"openTimeout="00:05:00"sendTimeout="00:05:00"maxBufferPoolSize="1048576000"maxReceivedMessageSize="1048576000">
<readerQuotasmaxDepth="640"maxStringContentLength="1048576000"maxArrayLength="1048576000"maxBytesPerRead="1048576000"maxNaMetableCharCount="1048576000"/>
<securitymode="None">
<messageclientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
在客户端的配置如下:
<bindingname="BasicHttpBinding_IReseiverService"maxReceivedMessageSize="104857600">
</binding>
在windows10系统中运行,客户端能正常访问,但是在windows7系统中就会出现上面的异常信息,通过尝试,需在客户端配置与服务端一样的配置。结果如下:
<bindingname="BasicHttpBinding_IReseiverService"maxReceivedMessageSize="104857600">
<readerQuotasmaxDepth="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>
<behaviorname="NewBehavior">
<dataContractSerializermaxItemsInObjectGraph="65536000"/>
</behavior>
</endpointBehaviors>
</behaviors>

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

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

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念