【问题标题】:Max WCF message size exception even though it is configured最大 WCF 消息大小异常,即使已配置
【发布时间】:2014-09-24 02:22:25
【问题描述】:

我遇到了这个异常:

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

我的app.config如下:

<basicHttpBinding>
  <binding name="BasicHttpBinding_IContentServiceController" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
  <binding name="BasicHttpBinding_IAbstractServiceController" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
  <binding name="BasicHttpBinding_ISecurityServiceController" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />        
</basicHttpBinding>

【问题讨论】:

  • 这里没有问题。
  • 我遇到了同样的问题,我在后面的代码中使用 BasicHttpBinding bhb = new BasicHttpBinding(); bhb.MaxReceivedMessageSize = Int32.MaxValue; 来管理它

标签: wcf wcf-binding


【解决方案1】:

在客户端:

<system.serviceModel>
    <binding name="BasicHttpBinding_Service" allowCookies="false" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
        closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
        <readerQuotas maxDepth="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647"
            maxNameTableCharCount="2147483647"/>
    </binding>
    <client>
        <endpoint address="http://localhost:80/Service.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_Service" contract="WCF.IService"
            name="BasicHttpBinding_IService" />
    </client>
</system.serviceModel>

在服务器端:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_Service" allowCookies="false" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
                closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
        <readerQuotas maxDepth="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" 
                      maxNameTableCharCount="2147483647"/>
      </binding>
    </basicHttpBinding>    
  </bindings>
  <services>
    <service behaviorConfiguration="WCF.ServiceBehavior" name="WCF.Service">
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service" contract="WCF.IService">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="WCF.ServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

确保它们都为最大配额值配置了绑定。

【讨论】:

    【解决方案2】:

    即使您定义了具有最大配额的绑定,它们也不会生效,除非您将绑定分配给指定的端点 - 将使用绑定的默认值。在没有看到配置文件 &lt;system.serviceModel&gt; 的其他相关部分的情况下,您需要 a) 通过 bindingConfiguration 属性将绑定分配给特定端点或 b) 将其设置为默认绑定(对于 .NET 4.0 及更高版本) .

    由于您定义了 3 个绑定(全部用于 basicHttpBinding)选项 b 可能不合适(每个绑定只能有一个默认定义),因此选项 a 看起来像这样(对于服务):

    <services>
      <service name="myService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IContentServiceController" contract="MyService.IContentServiceController" />
      </service>
    </services>
    

    客户端看起来非常相似:

    <client>
      <endpoint address="http://someaddress/" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IContentServiceController" contract="MyService.IContentServiceController" />
    </client>
    

    【讨论】:

      猜你喜欢
      • 2010-12-15
      • 2013-11-03
      • 2010-09-27
      • 2020-10-06
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      相关资源
      最近更新 更多