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

时间:2012-10-05 18:47:35

标签: .net wcf

好的,我不知道发生了什么。我在这里发现了一堆帖子,但是他们都说了几乎相同的事情:更改客户端和服务器中的maxStringContentLength。我已经做了那么多,但我仍然得到同样的该死的错误。我也试过以编程方式更改最大长度,但没有骰子。

服务器上的Web.config:

  <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" 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="2147483647" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="320" maxStringContentLength="2147483647" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:52826/Service1.svc" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IService1"
      contract="ServiceReference1.IService1"
      name="BasicHttpBinding_IService1">        
  </endpoint>
</client>


<behaviors>
  <endpointBehaviors>
    <behavior name="wsServiceBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483646" />
    </behavior>
  </endpointBehaviors>

  <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="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

并在客户端:

  <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" 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="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:52826/Service1.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
    name="BasicHttpBinding_IService1" />
</client>

当我运行服务时,我也注意到了。生成的配置文件列出了maxStringContentLength =“8192”。我已经尝试关闭“始终在启动服务时重新生成配置文件”选项并直接编辑配置文件以增加最大值,但它仍然无效。

- EDIT-- 看来该服务实际上没有像Eugune所提到的那样接收配置。我补充说:

    <services>
  <service name="Courrier.myService">
    <endpoint address="http://localhost:52826/Service1.svc" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IService1"
    contract="ServiceReference1.IService1">
    </endpoint>
  </service>
</services>

但仍然无效?

2 个答案:

答案 0 :(得分:3)

当我在客户端看到此错误时,通常意味着该服务引发了异常。如果您为Web服务启用了显示错误,则异常中的堆栈跟踪很容易会导致8192字符串限制。

答案 1 :(得分:1)

您确定您确实更改了服务器上的配额吗?在“服务器”配置中,您可以使用增加的配额定义BasicHttpBinding_IService1绑定,但之后只能在&lt; client&gt;中使用它。部分。