【问题标题】:The maximum string content length quota (8192) has been exceeded.Increase the MaxStringContentLength property on the XmlDictionaryReaderQuotas已超过最大字符串内容长度配额 (8192)。增加 XmlDictionaryReaderQuotas 上的 MaxStringContentLength 属性
【发布时间】:2013-04-02 12:49:00
【问题描述】:

当我将实体对象传递给 WebService 时出现以下错误

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

我尝试通过在 Webservice 的 webconfig 中提供以下代码来解决此问题,但错误仍然存​​在。谁能帮忙!!!!!!

 <bindings>
      <wsHttpBinding>
        <binding name="MyService" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                   maxNameTableCharCount="2147483647" />
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

【问题讨论】:

  • 提供客户端和服务器端绑定。正如@peer 指出的那样,肯定存在不匹配导致此错误
  • 正如@Dhawalk 所说,您可以发布完整的服务配置吗?即使您可能为绑定定义了更大的值,也有可能由于几个原因(取决于您的配置中的内容以及您使用的 .NET 版本),它们可能不会被使用。

标签: c# wcf web-config


【解决方案1】:

您必须在服务器和客户端上设置最大字符串内容长度配额。所以检查你的客户端配置。如果这不起作用,请检查您是否使用了正确的绑定。

【讨论】:

  • 好吧,我很确定我正在使用 HTTPS 绑定,所以我在我的项目中尝试了一个新的绑定以及 web 服务 web config
  • 您在服务器上有一个 wsHttpBinding 绑定,在您的客户端上有一个 basicHttpBinding。我确定其中一个不正确,请检查您的服务器和客户端绑定并启动 wcf 日志记录。 google.nl/…
  • 第一次在 Visual Studio 中创建服务引用时,您的 Web 服务不是 HTTPS 吗?如果是这样,作为一个快速而肮脏的解决方案,您可以尝试删除您的引用,从 ServiceReferences.ClientConfig 中删除条目,然后从您现有的 Web 服务中重新添加它。
【解决方案2】:

您的服务器端 Web 配置允许使用大字符串,但您还需要修改客户端 ServiceReferences.ClientConfig 文件以反映这一点。

<configuration>
  <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="Binding_MyService">
                <binaryMessageEncoding />
                <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="yourserviceurlhere"
            binding="wsHttpBinding" bindingConfiguration="Binding_MyService"
            contract="yourcontracthere" name="MyService" />
    </client>
</system.serviceModel>

【讨论】:

  • 但是我在某处读到我们在使用 WCF Web 服务时不需要创建自定义绑定
  • 你不知道,这实际上是我从自己的项目中提取的一些修改代码。如果您的 silverlight 客户端使用 basichttpbinding,那很好。确实如此,正如我从您对同行评论的回复中看到的那样。
  • 从技术上讲,如果这只发生在连接的一侧,您只需修改该侧的配置文件。换句话说,如果发送到服务失败,修改服务的配置文件。如果发生在客户端,只需要修改客户端配置文件即可。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-15
  • 1970-01-01
相关资源
最近更新 更多