WCF MaxReceivedMessageSize:超出最大邮件大小配额

时间:2009-10-15 16:42:34

标签: wcf

我收到此错误:

  

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

如何在WCF客户端应用程序或服务器应用程序中增加此值,并在可能的情况下举例说明如何执行此操作?

3 个答案:

答案 0 :(得分:19)

您可以在app / web.config中的客户端增加它:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="WSBigQuotaConfig" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2097152" maxBufferPoolSize="524288" maxReceivedMessageSize="2097152" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="2097152" maxArrayLength="2097152" 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://example.com/endpoint.svc"
          binding="basicHttpBinding"
          bindingConfiguration="WSBigQuotaConfig"
          contract="ISomeServiceContract" />
  </client>
</system.serviceModel>

答案 1 :(得分:3)

您需要在绑定配置中设置MaxReceivedMessageSize属性。默认情况下,它是65536.我假设你正在使用数据集或那种性质最终相当大的东西(主要是因为它们通常用XML表示)。

好消息是,我认为您只需要在客户端配置中更改此设置。看看下面。

<bindings>
   <netTcpBinding>
      <binding name="MyTcpBinding"
               maxReceivedMessageSize="2000000"/>
   </netTcpBinding>
<bindings>

答案 2 :(得分:1)

  

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_Username" maxReceivedMessageSize="20000000"          maxBufferPoolSize="20000000">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" establishSecurityContext="false"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<client>
  <endpoint
            binding="wsHttpBinding"
            bindingConfiguration="wsHttpBinding_Username"
            contract="Exchange.Exweb.ExchangeServices.ExchangeServicesGenericProxy.ExchangeServicesType"
            name="ServicesFacadeEndpoint" />
</client>