【问题标题】:Sending larger object to WCF results in 400 Bad Request将较大的对象发送到 WCF 会导致 400 Bad Request
【发布时间】:2011-09-23 04:20:09
【问题描述】:

我有一个单元测试将一个中等大小的对象发送到 WCF 服务。如果我为该参数传递 null,则一切正常。当我发送一个填充对象时,我得到一个 HTTP 400 响应。

WCF 跟踪显示此错误:

传入邮件的最大邮件大小配额 (65536) 已达到 超过了。

但是,我在 app.config 中为单元测试项目设置了大小配置参数,如下所示:

<basicHttpBinding>
    <binding name="BasicHttpBinding_IMyAppService" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="200000000" maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
        <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
    </binding>
</basicHttpBinding>

我的配置中缺少什么以将允许的消息大小提高到错误消息中看到的 65536 以上?

更新:

Web 服务主机的 web.config 文件还将 maxReceivedMessageSize 设置为一个较大的值(我认为):

<binding name="basicHttpBindingConfig" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
  <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
  <security mode="TransportCredentialOnly">
    <transport clientCredentialType="Ntlm"/>
  </security>
</binding>

【问题讨论】:

    标签: wcf-binding


    【解决方案1】:

    如果我正确理解您的问题,您在单元测试的 app.config 中增加了“maxReceivedMessageSize”的大小。实际上,您应该在您从单元测试代码调用的 Web 服务的 app.config/web.config 中进行此更改。如果您在 IIS 中托管您的 Web 服务,那么它将是 web.config。如果您在 Windows 服务中托管它,那么您需要在 app.config 中进行更改(它会移动到您的 bin 文件夹中的 .exe.config 文件中。

    【讨论】:

    • 对不起,我把那部分从我原来的问题中遗漏了。我还在 Web 服务的 web.config 中设置了 maxReceivedMessageSize。使用特定配置更新问题。你觉得那里有问题吗?
    • 您在哪里托管 Web 服务?如果它托管在 Windows 服务中,请检查 appname.exe.config(其中 appname 是您的应用程序名称)的配置设置。重新编译时配置文件通常会自动更新。
    • 现在,它托管在 VS 2010 的网站项目中。该项目有一个 web.config(相关部分现在发布在问题中)
    • 鉴于原始问题,我认为您的答案非常完整,因此我将接受它。我发现了更多,但会为此提出一个新问题。谢谢!
    猜你喜欢
    • 2016-05-06
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 2021-11-04
    • 1970-01-01
    • 2014-08-25
    • 2017-08-17
    相关资源
    最近更新 更多