错误400(错误的请求):maxReceivedMessageSize没有考虑到我的WCF服务 [英] Error 400 (bad request): maxReceivedMessageSize not taken into account for my WCF service

查看:205
本文介绍了错误400(错误的请求):maxReceivedMessageSize没有考虑到我的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有对SO(几乎相同标题)的多个相关问题,没有人帮我   解决我的问题。前请不要关闭我的问题是重复的   阅读它。谢谢你。

There are multiple related questions on SO (almost same title), none of them helped me to fix my problem. Please do not close my question as duplicate before reading it. Thanks.

我目前使用WCF暴露一个We​​b服务(SOAP,HTTP)。它被部署在IIS防爆preSS现在。我的问题是,我不能管理从我的客户端消耗我的服务。我的客户端接收 HTTP错误400错误请求例外。

I'm currently using WCF to expose a webservice (SOAP, HTTP). It is deployed in IIS Express for now. My problem is, I can't manage to consume my service from my client. My client receives a HTTP Error 400 Bad request exception.

我再启动跟踪在服务器端,看看有什么实际发生的事情,这是我得到:

I've then activated tracing on server side to see what's actually happening, here's what I get:

我翻译的错误信息成英文:的最大邮件大小配额传入消息(65536)已被超过。为了增加配额,使用MaxReceivedMessageSize属性相应绑定元素上。

I've translated the error message into English: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element..

pretty的不言自明的,真的。由于我的SOAP消息是相当沉重的,它很可能超过64KB的限制。

Pretty self-explanatory, actually. As my SOAP message is quite heavy, it probably exceeds the limit of 64KB.

我决定扩大这个限制在绑定配置。因此,这里是我的web.config(服务器端):

I decided to extends this limit in the binding configuration. So here's my web.config (server side):

<services>
  <service name="MyServiceName">
    <endpoint binding="basicHttpBinding"
              bindingConfiguration="MyBindingConfiguration"
              bindingNamespace="http://my_namespace"
              contract="XXX.IMyContract" />
  </service>
</services>

<bindings>
  <basicHttpBinding>
    <binding name="MyBindingConfiguration"
             allowCookies="true"
             maxReceivedMessageSize="2147483647"
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="32" maxArrayLength="2147483647" maxStringContentLength="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>

正如你所看到的,所有的大小设置为 int.MaxValue

我也修改了我的客户端的app.config,那就是:

I've also modified my client app.config, here it is:

<bindings>
  <basicHttpBinding>
    <binding name="MyBindingName"
             allowCookies="false"
             bypassProxyOnLocal="false"
             hostNameComparisonMode="StrongWildcard"
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647"
             maxReceivedMessageSize="2147483647"
             messageEncoding="Text"
             textEncoding="utf-8"
             transferMode="Buffered"
             useDefaultWebProxy="true">

      <readerQuotas maxDepth="32"
                    maxStringContentLength="2147483647"
                    maxArrayLength="16384"
                    maxBytesPerRead="4096"
                    maxNameTableCharCount="16384" />

      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>

    </binding>
  </basicHttpBinding>
</bindings>

<client>
  <endpoint address="http://localhost:8083/myAddress.svc"
            binding="basicHttpBinding"
            bindingConfiguration="MyBindingName"
            contract="IMyContract"
            name="MyBindingName" />
</client>

我再重新部署我的服务,这个问题仍然在这里( HTTP 400错误请求在客户端+ MaxReceivedMessageSize限制在65536 在服务器端)。

I then redeployed my service, and the issue was still here (HTTP 400, Bad request on client side + MaxReceivedMessageSize limited to 65536 on server side).

然后,我测试了一个很小的SOAP消息,我的服务:一切都完美的罚款。所以这个问题是真的,我的消息不大于64KB。

I then tested my service with a very small SOAP message: everything is perfectly fine. So the problem is really that my message is bigger than 64KB.

我花了2小时昨日试图找出什么是我的配置...可能是一些明显的问题,但我找不到......

I spent 2 hours yesterday trying to figure out what's the problem with my configuration... Probably something obvious, but I can't find...

我GOOGLE了很多关于这个问题,95%的时间问题是开发商忘了指定的服务端点的 bindingConfiguration 属性。正如你可以在我的web.config上面看,这对我来说OK。

I've googled a lot about this problem, 95% of time the issue is the developer forgot to specify the bindingConfiguration attribute in the service endpoint. As you can see in my web.config above, it's OK for me.

然后我发现<一href="http://stackoverflow.com/questions/9910566/wcf-binding-configuration-apply-only-as-default-but-as-named-it-fails#comment12845134_9910566">another问题计算器上对(几乎)同样的问题。

由于在他的问题上撰文称,的绑定配置的名称设置为的String.Empty 修复的问题:

As the author said in his question, setting the name of the binding configuration to string.Empty "fixes" the problem:

<services>
  <service name="MyServiceName">
    <endpoint binding="basicHttpBinding"
              bindingConfiguration=""
...

<bindings>
  <basicHttpBinding>
    <binding name=""
...

在使用默认绑定,一切工作正常。使用此解决方法,我不能只是解决我的问题,因为我需要在同一个web.config中指定多个不同的绑定配置。

When using the default binding, everything works fine. I can't just fix my problem using this workaround because I need to specify multiple different binding configurations in the same web.config.

我再造一个问题在这里,因为它实际上并不是在相同的条件。我的服务是不是自托管,但是托管在IIS防爆preSS(或IIS 7.5,经过测试,相同的问题)

I'm recreating a question here because it's not actually the same conditions: my service is not self-hosted but hosted in IIS Express (or IIS 7.5, tested, same problem).

我已经找到了这里带有自托管服务,这个问题是与此相关的特殊性。因此,我认为也有一些是那些2 SO问题是不同的。

I've found a similar issue here with a self-hosted service, and the issue was related to this particularity. So I think there is something different between those 2 SO questions.

我想有一些明显的错误在我的配置,但我找不到什么。 任何帮助AP preciated。

I guess there's something obviously wrong in my configuration, but I can't find what. Any help appreciated.

推荐答案

一切似乎是美好的第一眼 - 唯一的一点是:&LT;服务名称=...&GT ; 属性必须匹配完全以您的完全合格的服务实现类(包括所有的命名空间等) - 是那么回事?

Everything seems to be fine at first glance - only point is: the <service name="....."> attribute must match exactly to your fully-qualified service implementation class (including all namespaces etc.) - is that the case??

我问,因为你有合同=XXX.IMyContract表示一个命名空间,但你的&LT;服务名称=.... &GT; 属性不具有任何空间暗示

I ask because you have contract="XXX.IMyContract" indicating a namespace, but your <service name="...."> attribute doesn't have any namespace hinted at.

这篇关于错误400(错误的请求):maxReceivedMessageSize没有考虑到我的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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