0

我收到一个错误

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

3 回答 3

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 并且问题解决了

于 2012-09-19T05:18:08.617 回答
1

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

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

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

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

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

- 更新

向绑定添加了 maxReceivedMessageSize 属性。

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

于 2012-09-19T04:38:47.453 回答
0

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

于 2012-09-19T04:38:56.070 回答