【问题标题】:WCF Config to fix The maximum string content length quota (8192) has been exceededWCF Config to fix 已超出最大字符串内容长度配额 (8192)
【发布时间】:2012-09-19 13:18:08
【问题描述】:

我收到一个错误

已超过最大字符串内容长度配额 (8192)

我知道我需要修改我的 WCF 配置,但我无法让它工作。这是我目前所拥有的:我尝试使用内置的 WCF 编辑器。

    <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding>
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </wsHttpBinding>
    </bindings>

    <client>
      <remove contract="IMetadataExchange" name="sb" />
      <endpoint address="" binding="netTcpRelayBinding" contract="IMetadataExchange"
        name="sb" />
    </client>
    <services>
      <service name="SvcLibrary.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/SvcLibrary/Service1/"/>
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="wsHttpBinding" contract="SvcLibrary.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    SCB 关于绑定是正确的:

    <bindings>
          <wsHttpBinding>
            <binding>
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
          </wsHttpBinding>
        </bindings>
    

    但我也收到错误“已超出最大字符串内容长度配额 (8192)”,因为我需要按如下方式修改客户端应用程序:

     <basicHttpBinding>
            <binding name="BasicHttpBinding_IXRMService" 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="65536" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None"
                  realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
          </basicHttpBinding>
    

    默认的maxStringContentLength设置为8192我把它增加到65536,问题解决了

    【讨论】:

      【解决方案2】:

      您需要按如下方式更改绑定部分:

      <bindings>
            <wsHttpBinding>
              <binding maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                  maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              </binding>
            </wsHttpBinding>
          </bindings>
      

      您的端点指定它正在使用 wsHttpBinding,但您只配置了 basicHttpBinding。

      这意味着您的服务将只使用默认值

      由于您指定的值很大,您可能需要查看这些值

      -- 更新

      为绑定添加了 maxReceivedMessageSize 属性。

      您还可以确认您是否在客户端进行了任何更改。基本上客户端和服务器配置都应该匹配。

      【讨论】:

      • 我做了这个改变,但我仍然得到同样的错误。我还需要编辑端点部分吗?
      • 您是否删除了绑定上的名称使其与上述相同?
      • 现在看起来像这样:
      【解决方案3】:

      您设置了正确的属性 (maxStringContentLength),但绑定错误。问题是您正在为basicHttpBinding 定义配置,但在服务端点上使用wsHttpBinding。将绑定配置更改为wsHttpBinding,它应该可以正常工作(您可能想验证是否需要通过wsHttpBinding 提供的WS-* 功能,您也可以将端点的绑定更改为basicHttpBinding,这也可以,只要你不需要支持分布式事务等)

      【讨论】:

      • 仍然得到“最大字符串内容长度配额(8192)”
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      相关资源
      最近更新 更多