即使已配置,也会出现最大WCF消息大小异常

时间:2014-09-23 13:59:58

标签: wcf wcf-binding

我得到了这个例外:

  

已超出传入邮件的最大邮件大小限额(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>

2 个答案:

答案 0 :(得分:0)

在客户端:

<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>

确保它们都具有配置最大配额值的绑定。

答案 1 :(得分:0)

即使您已定义具有最大配额的绑定,除非您将绑定分配给指定的端点,否则它们将不会生效 - 将使用绑定的默认值。在没有看到配置文件的<system.serviceModel>的其他相关部分的情况下,您需要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>