WCF服务错误 - 已超出传入邮件的最大邮件大小限额(65536)

时间:2014-01-13 21:49:22

标签: asp.net wcf silverlight wcf-binding

所有

我有一个WCF服务(在asp.net 4.0网络应用程序中),在asp.net兼容模式下运行。 当我的silverlight客户端将大量数据发布到服务Save(SomeLargeObject)时,我从服务器收到此消息(400-Bad Request)。我在服务器上跟踪了错误并从服务中得到了这个:

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

要解决此错误,我已更新了我的服务器服务配置文件(web.config):

<bindings>
      <basicHttpBinding>
        <binding name="WebStoreServices_BasicHttpBinding" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
      <wsHttpBinding>
        <binding name="MyBinding" maxReceivedMessageSize="2147483647" />
      </wsHttpBinding>
      <webHttpBinding>
        <binding name="NewBinding0" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
      </webHttpBinding>
    </bindings>

和我的Silverlight客户端服务配置文件:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IWebStoreServices" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:1271/Services/WebStoreServices.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWebStoreServices"
                contract="WebStore.IWebStoreServices" name="BasicHttpBinding_IWebStoreServices" />
        </client>
    </system.serviceModel>

我仍然在服务器上收到上述错误,“传入邮件的最大邮件大小配额(65536)”,就像我在服务器上的绑定被忽略一样。为什么忽略我的设置!我确实使用WCF工具来创建绑定以避免错误。

1 个答案:

答案 0 :(得分:2)

设置看起来很好 - 但使用basicHttpBinding 的服务器端端点是否实际引用了那个绑定配置与增加的MaxReceivedMessageSize设置?

您应该在服务器端web.config中设置类似的设置:

<services>
   <service name="WebStore.WebStoreServices">
       <!-- this endpoint uses basicHttpBinding and uses the binding configuration -->
       <endpoint name="basicHttp"
           address="......"
           binding="basicHttpBinding"
           bindingConfiguration="WebStoreServices_BasicHttpBinding" 
           contract="WebStore.IWebStoreServices" />
   </service>
</services>

如果您的basicHttpBinding端点缺少 bindingConfiguration="..."设置 - 那么,您已经定义了绑定配置,但实际上您并未使用它!

相关问题