我正在使用 .NET、C# 应用程序,它打算将长 XML 字符串发送到 WCF 服务方法以进行进一步操作。当我的应用程序尝试在运行时将 XML 字符串发送到 WCF 服务时,我收到一条错误消息:
“格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数 http://tempuri.org/:strProdUserDataXML 时出错。InnerException 消息是‘反序列化System.String 类型的对象。读取 XML 数据时已超过最大字符串内容长度配额 (8192)。可以通过更改创建 XML 阅读器时使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性来增加此配额。第 131 行,位置 57 .'。有关更多详细信息,请参阅 InnerException。”
我的应用程序端 web.config 我将“绑定(bind)”和“端点”写为:
<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" />
如果有人可以帮助我解决这个错误,我将非常感激。 在此先感谢大家。
最佳答案
这是 MSDN 上关于 Reader Quotas 的文章.
似乎超出了您服务器端的其中一个读者配额。
具体来说,超过了 maxStringContentLength。 maxStringContentLength 的默认值为 8192 个字符,如错误消息所述,已超出。
但正如其他一些人所建议的那样,将所有值都增加到最大值 2147483647 可能不是最好的方法。
如我链接的 MSDN 文档中所写:
The complexity constraints provide protection from denial of service (DOS) attacks that attempt to use message complexity to tie up endpoint processing resources. Other complexity constraints include items such as a maximum element depth and a maximum length for string content within the message.
再加上您当前将安全模式设置为无 - 您可能会遇到一些问题。
关于c# - 将 XML 字符串发送到 WCF 时出现 "The maximum string content length quota (8192) has been exceeded while reading XML data"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15654892/