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

时间:2011-03-28 13:30:22

标签: wcf basichttpbinding

我为几个表创建范围时遇到此异常,所有这些表都设计很大

<bindings>
    <wsHttpBinding>
        <binding name="wsHttpBinding_ISyncServices" closeTimeout="00:10:00"
            openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
            transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
            <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                maxNameTableCharCount="2147483647" />
            <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
            <security mode="Message">
                <transport clientCredentialType="Windows"
                    proxyCredentialType="None" realm="">
                    <extendedProtectionPolicy policyEnforcement="Never" />
                </transport>
                <message clientCredentialType="Windows"
                    negotiateServiceCredential="true" algorithmSuite="Default" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>

我已将MaxReceivedMessageSize发送至2147483647 但它仍然在这条线下给我低于例外

 client.GetTableDescription(scopeName, syncTable)
  

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

9 个答案:

答案 0 :(得分:101)

根据this question's answer

  

你会想要这样的东西:

<bindings>
     <basicHttpBinding>
         <binding name="basicHttp" allowCookies="true"
 maxReceivedMessageSize="20000000"
 maxBufferSize="20000000"
 maxBufferPoolSize="20000000">
             <readerQuotas maxDepth="32"
 maxArrayLength="200000000"
 maxStringContentLength="200000000"/>
         </binding>
     </basicHttpBinding> </bindings>

请同时阅读对那里接受的答案的评论,其中包含有价值的意见。

答案 1 :(得分:12)

您还需要增加maxBufferSize。另请注意,您可能需要增加readerQuotas

答案 2 :(得分:9)

您需要在SERVER和CLIENT上的绑定配置(在app.config文件中)进行更改,否则它将不会生效。

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding maxReceivedMessageSize="2147483647 " max...=... />
        </basicHttpBinding>
       </bindings>
</system.serviceModel>

答案 3 :(得分:6)

如果您使用的是CustomBinding,则需要在httptransport元素中进行更改。 将其设置为

<customBinding> <binding ...> ... <httpsTransport maxReceivedMessageSize="2147483647"/> </binding> </customBinding>

答案 4 :(得分:5)

这对我有用:

 Dim binding As New WebHttpBinding(WebHttpSecurityMode.Transport)
 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
 binding.MaxBufferSize = Integer.MaxValue
 binding.MaxReceivedMessageSize = Integer.MaxValue
 binding.MaxBufferPoolSize = Integer.MaxValue

答案 5 :(得分:2)

对配置进行更改并没有帮助我。以下工作很好

private YourAPIClient GetClient()
    {
        Uri baseAddress = new Uri(APIURL);
        var binding = new BasicHttpBinding();
        binding.MaxReceivedMessageSize = 20000000;
        binding.MaxBufferSize = 20000000;
        binding.MaxBufferPoolSize = 20000000;
        binding.AllowCookies = true;
        var readerQuotas = new XmlDictionaryReaderQuotas();
        readerQuotas.MaxArrayLength = 20000000;
        readerQuotas.MaxStringContentLength = 20000000;
        readerQuotas.MaxDepth = 32;
        binding.ReaderQuotas = readerQuotas;
        if (baseAddress.Scheme.ToLower() == "https")
            binding.Security.Mode = BasicHttpSecurityMode.Transport;
        var client = new YourAPIClient(binding, new EndpointAddress(baseAddress));
        return client;
    }

答案 6 :(得分:1)

您还可以通过使用MTOM(消息传输优化机制)消息编码来部分解决此问题。WCF中的默认消息编码机制是Text,它的base64编码数据,Base64编码使消息大小膨胀了大约33%。 / p>

MTOM不对数据进行base64编码。这也意味着消除了对base64编码和解码数据的额外处理开销。因此,MTOM可以显着提高整体邮件传输性能。

使用文本消息编码,二进制数据经过base64编码,并嵌入到SOAP信封中。对于MTOM,二进制数据作为MIME(多用途Internet邮件扩展)附件包含在内。

可以在配置文件中像这样进行配置。

<bindings>
  <wsHttpBinding>
    <binding name="wsHttp" messageEncoding="Mtom"
             maxReceivedMessageSize="700000">
      <readerQuotas maxArrayLength="700000"/>
    </binding>
  </wsHttpBinding>
</bindings>

您可以比较并看到,与文本消息编码相比,MTOM接收到的字节要少得多。

答案 7 :(得分:0)

我的解决方案是在我的查询中使用“-OutBuffer 2147483647”参数,该参数是公共参数的一部分。 PS C:&gt; Get-Help about_CommonParameters -Full

答案 8 :(得分:0)

对我来说,web.config / app.config中的设置被忽略了。我最终手动创建了绑定,这为我解决了这个问题:

var httpBinding = new BasicHttpBinding()
{
    MaxBufferPoolSize = Int32.MaxValue,
    MaxBufferSize = Int32.MaxValue,
    MaxReceivedMessageSize = Int32.MaxValue,
    ReaderQuotas = new XmlDictionaryReaderQuotas()
    {
        MaxArrayLength = 200000000,
        MaxDepth = 32,
        MaxStringContentLength = 200000000
    }
};