16

我有一个用于 WCF 服务的以下服务器端 app.config:

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="default" maxReceivedMessageSize="5000000">
          <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Core.TOAService.Service1Behavior"
        name="Core.TOAService.TOAService">
        <endpoint address="" binding="wsHttpBinding" contract="Core.TOAService.ITOAService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/Core.TOAService/TOAService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Core.TOAService.Service1Behavior">
          <!-- 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>
  </system.serviceModel>

当我尝试将此服务传递给一个较大的文件(仅 ~250KB)时,我在 svclog 文件中记录了一个异常:

已超出传入邮件 (65536) 的最大邮件大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。

从配置顶部的绑定部分可以看出,我尝试将 maxReceivedMessageSize 设置为 5000000,但服务仍然认为它设置为默认值 65536。关于什么是错误的或哪个是“适当的”的任何想法“绑定元素?

4

3 回答 3

28

<binding>还有更多设置 :-) 在标签上尝试“maxBufferPoolSize”和“maxBufferSize” 。

但最大的问题是:您的端点没有引用该绑定配置!

<endpoint address="" 
          binding="wsHttpBinding" contract="Core.TOAService.ITOAService">

您需要添加对它的引用以使其变得有用 - 仅将其称为“默认”是行不通的.....

<endpoint address="" 
          binding="wsHttpBinding" 
          bindingConfiguration="default"
          contract="Core.TOAService.ITOAService">

您领先于时代 ;-) 在 WCF 4(使用 .NET 4.0 - 2009 年晚些时候)中,您将能够定义“默认绑定配置”,而无需显式命名和引用它们 - 但现在,您需要在端点及其绑定和您拥有的任何绑定(或行为)配置之间创建链接!

马克

于 2009-08-27T20:42:53.083 回答
16

如果您在使用 WCF 测试客户端时仍然收到此错误消息,那是因为客户端具有单独的MaxBufferSize设置。

要更正此问题:

  1. 右键单击树底部的配置文件节点
  2. 选择使用 SvcConfigEditor 编辑

将出现一个可编辑设置列表,包括 MaxBufferSize。

注意: 默认情况下,自动生成的代理客户端还将 MaxBufferSize 设置为 65536。

于 2010-08-05T06:10:24.853 回答
1

有几个地方需要设置大小。在您的情况下,我认为您需要添加读取配额。这是一个例子:

  <basicHttpBinding>
    <binding name="httpBasicBinding_Service" closeTimeout="00:03:00"
      openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00"
      maxBufferSize="2000001"
      maxBufferPoolSize="2000001" maxReceivedMessageSize="2000001">
      <readerQuotas maxDepth="2000001" maxStringContentLength="2000001"
        maxArrayLength="2000001" maxBytesPerRead="2000001" maxNameTableCharCount="2000001" />
    </binding>
  </basicHttpBinding>
于 2009-08-27T20:46:38.583 回答