【问题标题】:WCF service 400 bad requestWCF 服务 400 错误请求
【发布时间】:2012-04-27 01:09:36
【问题描述】:

我创建了一个接收大文件的服务。之后,我将其发布在本地 IIS7 上。之后,我创建了带有服务参考的测试客户端。当我尝试将大文件发送到服务器时,我得到了:Bad request (400)

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

服务器配置:

  <system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2097151" useFullyQualifiedRedirectUrl="true" executionTimeout="14400"/>
<customErrors mode="Off" /></system.web>

绑定

      <wsHttpBinding>
    <binding name="wsBufferedHttpsBinding" messageEncoding="Mtom" 
             maxReceivedMessageSize="11534336" maxBufferPoolSize="524288"
             sendTimeout="00:05:00" receiveTimeout="00:05:00" openTimeout="00:05:00" closeTimeout="00:05:00" >
      <readerQuotas maxDepth="64" maxStringContentLength="11534336" maxArrayLength="11534336"
          maxBytesPerRead="11534336" maxNameTableCharCount="16384" />
    </binding>
  </wsHttpBinding>

服务

      <service name="MyService">
    <endpoint address=""
              binding="wsHttpBinding"
              bindingName="wsBufferedHttpsBinding"
              contract="IServiceContract">
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    <endpoint address="soap12IssuedToken" binding="customBinding"
      bindingConfiguration="soap12IssuedToken" name="soap12IssuedToken"
      bindingNamespace="http://url"
      contract="IServiceContract" />
  </service>

这项服务到底出了什么问题?我在任何地方都设置了这个消息大小。

【问题讨论】:

标签: .net wcf exception


【解决方案1】:

看起来主要问题是您的端点没有引用绑定配置。因此,您使用的是默认 65536。

还有其他一些事情需要检查:

  • 同一个合约有 2 个端点,您使用的是设置了 maxReceivedMessageSize 的那个吗?
  • 客户端的配置与服务器的配置是否匹配?
  • 您可能还需要设置“maxBufferPoolSize”和“maxBufferSize”

【讨论】:

    【解决方案2】:

    答案很简单:

     <endpoint address=""
              binding="wsHttpBinding"
              bindingName="wsBufferedHttpsBinding"
              contract="IServiceContract">
    

    我没有看到有 bindingName 而不是 bindingConfiguration

    【讨论】:

      【解决方案3】:

      我后来也遇到了这个问题,但后来我通过添加 dataContractSerializer maxItemsInObjectGraph="2147483646" 在服务的行为

      【讨论】:

        猜你喜欢
        • 2015-11-24
        • 1970-01-01
        • 2011-09-29
        • 2014-01-11
        • 1970-01-01
        • 1970-01-01
        • 2013-06-22
        • 2017-08-16
        • 1970-01-01
        相关资源
        最近更新 更多