【问题标题】:Fetching data from database using WCF使用 WCF 从数据库中获取数据
【发布时间】:2012-03-04 15:41:04
【问题描述】:

我调用了 WCF 服务并尝试在 Windows 7 中从数据库中获取数据。 我收到了这个错误。

反序列化操作回复消息正文时出错 'GetProductXml'。最大字符串内容长度配额 (8192) 有 读取 XML 数据时超出。此配额可能会增加 更改 MaxStringContentLength 属性 创建 XML 阅读器时使用的 XmlDictionaryReaderQuotas 对象。 第 13 行,位置 197。

我尝试在 WCF 服务的 Web 配置中将 MaxStringContentLength 属性更改为 2147483647,但我得到了与上述相同的错误....

【问题讨论】:

    标签: wcf


    【解决方案1】:

    您可以通过在 WCF 服务 web.config 以及客户端 web.config 中添加以下设置来解决该错误:

    <basichttpBinding>
        <binding>
            <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="64" maxNameTableCharCount="2147483647" />
        </binding>
    </basichttpBinding>
    

    注意:假设您使用的是 BasicHttpBinding。如果使用不同的绑定,请确保为该绑定添加 readerQuotas。

    如果您通过代码托管 WCF 服务,然后您想通过代码添加阅读器配额,请参见下文:

    var binding = new BasicHttpBinding();
    var myReaderQuotas = new XmlDictionaryReaderQuotas();
    myReaderQuotas.MaxStringContentLength = 5242880;
    binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null); 
    

    【讨论】:

      【解决方案2】:

      您需要在您在 Windows 7 应用程序中添加服务引用时创建的 client.config 文件中对其进行更改。

      【讨论】:

        猜你喜欢
        • 2012-12-14
        • 2016-11-21
        • 2014-04-10
        • 2016-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多