将较大的对象发送到 WCF 会导致 400 Bad Request

发布于 2024-12-06 11:22:22 字数 1689 浏览 2 评论 0原文

我有一个单元测试,将一个中等大小的对象发送到 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>

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 tracing shows this error:

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

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>

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

UPDATE:

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_失温 2024-12-13 11:22:22

如果我正确理解您的问题,您增加了单元测试的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文