gpt4 book ai didi

.net - 错误 400(错误请求): maxReceivedMessageSize not taken into account for my WCF service

转载 作者:行者123 更新时间:2023-12-04 18:24:10 33 4
gpt4 key购买 nike

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 来公开 Web 服务(SOAP、HTTP)。它现在部署在 IIS Express 中。我的问题是,我无法从客户那里使用我的服务。我的客户收到 HTTP Error 400 Bad request异常(exception)。

然后我在服务器端激活了跟踪以查看实际发生的情况,这就是我得到的:

enter image description here

我已将错误消息翻译成英文: 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. .

实际上,不言自明。由于我的 SOAP 消息很重,它可能超过了 64KB 的限制。

我决定在绑定(bind)配置中扩展这个限制。所以这是我的 web.config(服务器端):
<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,它是:
<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, Bad request 在客户端 + MaxReceivedMessageSize limited to 65536 在服务器端)。

然后我用一条非常小的 SOAP 消息测试了我的服务: 一切都很好 .所以问题实际上是我的消息大于 64KB。

我昨天花了 2 个小时试图找出我的配置有什么问题......可能很明显,但我找不到......

我在谷歌上搜索了很多关于这个问题的信息,95% 的问题是开发人员忘记指定 bindingConfiguration服务端点中的属性。正如您在上面的 web.config 中看到的那样,这对我来说没问题。

然后我找到了 another question on stackoverflow about the (almost) same issue .

正如作者在他的问题中所说,将绑定(bind)配置的名称设置为 string.Empty “修复”问题:
<services>
<service name="MyServiceName">
<endpoint binding="basicHttpBinding"
bindingConfiguration=""
...

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

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

我在这里重新创建一个问题,因为它实际上不是相同的条件:我的服务不是自托管的,而是托管在 IIS Express(或 IIS 7.5,经过测试,同样的问题)中。

我找到了 similar issue here使用自托管服务,问题与此特殊性有关。所以我认为这两个 SO 问题之间有些不同。

我想我的配置中有一些明显错误,但我找不到什么。
任何帮助表示赞赏。

最佳答案

乍一看,一切似乎都很好——唯一的一点是:<service name=".....">属性必须匹配 正是 到您完全合格的服务实现类(包括所有 namespace 等) - 是这样吗?

我问是因为你有 contract="XXX.IMyContract"表示命名空间,但您的 <service name="....">属性没有暗示任何命名空间。

关于.net - 错误 400(错误请求): maxReceivedMessageSize not taken into account for my WCF service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10041931/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com