已超出传入邮件的最大邮件大小限额(65536)

时间:2011-08-29 15:37:51

标签: .net wcf web-services configuration

我有一个WCF服务的以下配置。

即使我增加了maxReceivedMessageSize,服务仍会抛出错误:

  

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

如何解决这个问题?

  <system.serviceModel>
    <services>
      <service name="MyService" behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint address="http://localhost:22230/MyService.svc"
              binding="basicHttpBinding"
              bindingConfiguration="MyServiceBinding"
              contract="IMyService" />

        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors" >
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <basicHttpBinding>
        <binding name="MyServiceBinding"
               hostNameComparisonMode="StrongWildcard"
               receiveTimeout="00:10:00"
               sendTimeout="00:10:00"
               openTimeout="00:10:00"
               closeTimeout="00:10:00"
               maxReceivedMessageSize="6553600"
               maxBufferSize="6553600"
               maxBufferPoolSize="524288"
               transferMode="Buffered"
               messageEncoding="Text"
               textEncoding="utf-8"
               bypassProxyOnLocal="false"
               useDefaultWebProxy="true" >
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel

3 个答案:

答案 0 :(得分:15)

如果这是服务配置,您应该查看客户端配置并将maxReceivedMessageSize与服务器消息大小相匹配。消息来自您的客户。

答案 1 :(得分:4)

您需要在客户端配置中增加最大邮件大小。默认值为65536,加倍可能足以满足您的需求。

如果您以编程方式配置端点,则以下代码段可能有所帮助:

BasicHttpBinding binding = new BasicHttpBinding() { MaxReceivedMessageSize = 131072 };

然后,在实例化服务客户端时,将此绑定对象传递给构造函数。例如:

MyServiceClient client = new MyServiceClient(binding, "http://www.mysite.com/MyService/");

答案 2 :(得分:0)

请务必复制新的App.config

相关问题