【问题标题】:WCF: The maximum string content length quota (8192) has been exceededWCF:已超出最大字符串内容长度配额 (8192)
【发布时间】:2012-10-10 00:10:21
【问题描述】:

好吧,我不知道发生了什么。我在这里和谷歌搜索中找到了一堆帖子,但他们都说几乎相同的事情:更改客户端和服务器中的 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"。我尝试关闭“启动服务时始终重新生成配置文件”选项并直接编辑配置文件以增加最大值,但它仍然不起作用。

--编辑-- 看来该服务实际上并没有像 Eugune 提到的那样选择配置。我添加了:

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

但还是不行?

【问题讨论】:

    标签: .net wcf


    【解决方案1】:

    当我在客户端看到这个错误时,通常意味着服务抛出了异常。如果您为 Web 服务打开了显示错误,异常中的堆栈跟踪很容易突破 8192 字符串限制。

    【讨论】:

    • 我正在将文本文件读入字符串并将其发送到服务。长度计数约为 11k。当我在字符串中硬编码而不是读取文件时,一切正常。所以我认为不会引发错误。
    • @user850237 - 您可以发布您将文本文件读取为字符串的代码吗?该代码中的某些内容可能会引发异常,而对字符串进行硬编码则不会。
    • 我真的不这么认为。我正在客户端将文件读取到字符串中,然后将其发送。 ServiceReference1.Service1Client sc = new Service1Client(); TextReader tr = new StreamReader(emailPath); var inputEmail = tr.ReadToEnd(); var emailSend = sc.SendEMail(fromEmailAddress, subject, inputEmail, toEmailAddress, "nothing", url, true, 32, 100, 100);
    【解决方案2】:

    您确定您确实更改了服务器上的配额吗?在您的“服务器”配置中,您定义了一个具有增加配额的 BasicHttpBinding_IService1 绑定,但随后您只能在 部分中使用它。

    【讨论】:

    • 我想可能是这样。该服务似乎没有选择我创建的配置,而是采用了默认配置。我编辑了我的原始问题以添加我添加到服务器配置文件中的内容,但它仍然无法正常工作?
    猜你喜欢
    • 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
    相关资源
    最近更新 更多