将更大的对象发送到 WCF 导致 400 Bad Request [英] Sending larger object to WCF results in 400 Bad Request

查看:16
本文介绍了将更大的对象发送到 WCF 导致 400 Bad Request的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a unit test that sends a moderately large object to a WCF service. If I pass null for that parameter, everything works fine. When I send a populated object, I get an HTTP 400 response.

WCF 跟踪显示此错误:

WCF tracing shows this error:

传入消息的最大消息大小配额 (65536) 已达到超过.

The maximum message size quota for incoming messages (65536) has been exceeded.

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

However, I have cranked up the size configuration parameters in app.config for the unit test project as follows:

<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 以上?

What am I missing in my configuration to raise the allowed message size above the 65536 seen in the error message?

更新:

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

The web.config file for the web service host also sets the maxReceivedMessageSize to a large value (I think):

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

推荐答案

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

If I understand your question correctly, you increased the size for 'maxReceivedMessageSize' in the unit test's app.config. Actually you should make this change in the app.config/web.config of the web service which you are calling from your unit test code. If you host your web service in IIS, then it will be web.config. If you host it in windows service, then you need to make the change in the app.config (which gets moved to your .exe.config file in your bin folder.

这篇关于将更大的对象发送到 WCF 导致 400 Bad Request的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆