maxStringContentLength

maxStringContentLength

我们正在尝试将一个大的 xml 字符串发送到 WCF 中的服务方法,但我们收到了错误



该错误建议增加 maxstringcontentlength,尽管我们不确定是否应该在客户端或服务器端或两者都执行此操作。我们已经尝试将两者都放入,但我们似乎仍然收到错误消息。我将在下面发布客户端和服务配置。我假设它们中的一个或两个存在问题,阻止了它的工作。

有什么建议么?

客户:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_ITESTService"
                closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false"
                hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288"
                maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8"
                transferMode="Buffered" useDefaultWebProxy="true">
               <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="4096"
                    maxNameTableCharCount="2147483647" />
               <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint name="BasicHttpBinding_ITESTService"
            address="http://localhost/TESTService.svc"
            binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_ITESTService"
            contract="TESTService.ITESTService" />
    </client>
</system.serviceModel>

服务器:
<system.serviceModel>
   <bindings>
      <basicHttpBinding>
          <binding
              name="BasicHttpBinding_Service1"
              maxBufferSize="2147483647"
              maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32"
              maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
       <service name="TESTService">
          <endpoint name="BasicHttpBinding_Service1"
              address="http://localhost/TESTService.svc"
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_Service1"
              contract="ITESTService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

最佳答案

thread 详细解释了如何正确指定服务器和客户端上的绑定(bind)设置以更改 MaxStringContentLength。

另一个 thread 也提供了关于使用 readerQuotas 的清晰有效的答案。

10-06 16:08