我正在使用一个.NET,C#应用程序,它打算将一个长的XML字符串发送到WCF Service方法以进行进一步的操作。当我的应用程序试图在运行时将XML字符串发送到WCF服务时,我收到一条错误消息:
"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:strProdUserDataXML. The InnerException message was 'There was an error deserializing the object of type System.String. 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 131, position 57.'. Please see InnerException for more details."
我的应用程序端绑定我已经将“web.config”和"endpoint“写成:
<binding name="EndPointHTTPGenericPortal" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<endpoint address="http://192.168.140.40/WcfGenericPortal_Service/Service1.svc" binding="basicHttpBinding" bindingConfiguration="EndPointHTTPGenericPortal" contract="IService1" name="EndPointHTTPGenericPortal" behaviorConfiguration="Graph" />
如果有人能帮助我解决这个错误,我将不胜感激。提前感谢所有人。
发布于 2013-03-27 17:22:59
我得到了这个错误,并通过在客户机和服务器配置中为服务添加此- MaxItemsInObjectGraph属性来解决此问题。
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
服务器端
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Service.Service1Behavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</system.serviceModel>
客户端
<behaviors >
<endpointBehaviors>
<behavior name="endpointbehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
</behaviors>
并且不要忘记将此行为应用于EndPoint behaviorConfiguration=的“端点行为”。
发布于 2013-08-17 17:56:17
尝试在绑定中设置以下内容。
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
它解决了我的问题。有关更多参考信息,请访问以下链接http://blogfornet.com/2013/08/the-maximum-string-content-length-quota-8192-has-been-exceeded-while-reading-xml-data/
发布于 2014-10-30 20:57:23
客户端绑定
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService11" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
messageEncoding="Text">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="KAMServiceDistributor">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:1234/xxxx/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService11"
contract="yourservice namespae" name="AnyName" />
</client>
</system.serviceModel>
服务配置文件:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding <b>maxReceivedMessageSize="2147483647"</b>>
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="Service">
<endpoint binding="basicHttpBinding" contract="IService" />
</service>
</services>
</system.serviceModel>
https://stackoverflow.com/questions/15654892
复制相似问题