要修复的WCF配置已超出最大字符串内容长度配额(8192)

时间:2012-09-19 04:27:58

标签: c# wcf

我收到错误

  

已超出最大字符串内容长度限额(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>

3 个答案:

答案 0 :(得分:2)

关于绑定的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并且问题已解决

答案 1 :(得分:1)

您需要更改绑定部分,如下所示:

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

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

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

顺便说一下,您指定的值很大,您可能想查看那些

- 更新

为绑定添加了maxReceivedMessageSize属性。

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

答案 2 :(得分:0)

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