【问题标题】:“The maximum string content length quota (8192) has been exceeded while reading XML data” error while sending string to WCF“读取 XML 数据时已超出最大字符串内容长度配额 (8192)”将字符串发送到 WCF 时出错
【发布时间】:2015-11-17 08:11:34
【问题描述】:

我在上述问题上参考了几个stackoverflow线程,但即使应用了提到的解决方案,我仍然得到同样的错误。

我根据thisthis调整了设置,所以我客户端中的web.config和WCF服务中的app.config如下所示:

web.config:

 <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding maxReceivedMessageSize="10485760" name="WSHttpBinding_IMessengerService">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </wsHttpBinding>
    </bindings>
     <behaviors >
  <endpointBehaviors>
    <behavior name="WSHttpBinding_IMessengerService">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </endpointBehaviors>
</behaviors>
    <client>
      <endpoint address="http://localhost:8005/MessengerService/Service" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMessengerService" contract="MessengerService.IMessengerService">
        <identity>
          <servicePrincipalName value="Local Network" />
        </identity>
      </endpoint>  
    </client>
  </system.serviceModel>

App.config:

<system.serviceModel>
<services>
  <!-- This section is optional with the new configuration model introduced in .NET Framework 4. -->
  <service name="Omnix.Messenger.Service.MessengerService" behaviorConfiguration="MessengerServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8005/MessengerService/Service" />
      </baseAddresses>
    </host>

    <!-- this endpoint is exposed at the base address provided by host: http://localhost:8005/MessengerService/service  -->
    <endpoint address="" binding="wsHttpBinding" contract="Omnix.Messenger.Service.Contract.IMessengerService" />

    <!-- the mex endpoint is exposed at http://localhost:8005/MessengerService/service/mex -->
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MessengerServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

谁能指出我做错了什么,以及如何解决这个问题?

【问题讨论】:

  • 您已经调整了我看到的消息大小,但我没有看到 maxBufferSize="20481000" maxBufferPoolSize="524288" 。在不增加缓冲区的情况下,更改最大消息大小毫无意义
  • 当我添加 maxBufefrSize 时,我收到一条错误消息,指出不允许这样做。似乎此属性不适用于 wsHttpBinding 绑定。
  • 好的。所以根据这个(social.msdn.microsoft.com/Forums/vstudio/en-US/…)你可以尝试只玩 maxBufferPoolSize
  • 是的,我做到了。我还尝试了 Ricado 的指示。问题仍然存在:(

标签: wcf request content-length


【解决方案1】:

您还需要在服务器端设置相同的配置。 在您的 app.config 中添加绑定配置:

 <system.serviceModel>
    <!-- add the lines below -->
    <bindings>
      <wsHttpBinding>
         <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" name="WSHttpBinding_IMessengerService">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
      </wsHttpBinding>
    </bindings>

同时更改 Web.config:

 <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" name="WSHttpBinding_IMessengerService">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>

希望对你有帮助

【讨论】:

  • 我已经更新了我的答案,在绑定标签中包含了 maxBuffer 和 maxReceive,请查看。
  • 就像我在 Mimas 的帖子中所说,maxBufferSize 不是 wsHttpBinding 的有效属性。
  • 是的,你是对的,wsHttpBinding中只使用了maxBufferPoolSize,对不起。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多