请求协助解决WCF服务调用MaxReceivedMessageSize超限报错问题
报错信息:
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.
调用端配置:
<bindings> <basicHttpBinding> <binding name="BasicHttp" bypassProxyOnLocal="true" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Buffered"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <security mode="None" /> </binding> </basicHttpBinding> <webHttpBinding> <binding name="WebHttp" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> </webHttpBinding> </bindings> <client> <endpoint address="http://xxx:7575/MyRequest.svc" behaviorConfiguration="webhttp" binding="webHttpBinding" bindingConfiguration="WebHttp" contract="MyService.Service.Contract.IRequestService" name="MyServiceEndpoint" /> </client>
服务端配置:
<system.serviceModel> <services> <service name="MyService.Service.RequestService" behaviorConfiguration="ServiceEndpointBehavior"> <endpoint address="" binding="webHttpBinding" contract="MyService.Service.Contract.IRequestService" behaviorConfiguration="RestEndPointBehavior" bindingConfiguration="WebHttp"/> </service> </services> <bindings> <basicHttpBinding> </basicHttpBinding> <webHttpBinding> <binding name="WebHttp" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"> <readerQuotas maxDepth="32" maxArrayLength="2147483647" maxStringContentLength="2147483647"/> </binding> </webHttpBinding> </bindings> </system.serviceModel>
已尝试同类问题解决方案但未生效,寻求帮助。
结合你的配置和报错特征,以下几点是核心排查方向:
补全服务端
readerQuotas的所有属性
服务端webHttpBinding的readerQuotas仅配置了3项,缺失maxBytesPerRead和maxNameTableCharCount,且maxDepth保留默认的32值。这些默认配额可能在处理复杂嵌套或大体积请求时触发限制,且WCF报错信息有时会误导性指向maxReceivedMessageSize。将服务端的readerQuotas调整为与客户端完全一致:<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>确认配置全局覆盖所有端点
检查服务端和客户端是否存在未指定bindingConfiguration的隐性端点(比如元数据端点、备用服务调用端点),这类端点会使用WCF默认的配额值(65536),可能导致偶发报错。确保所有涉及的端点都明确绑定了自定义的WebHttp配置。验证多环境配置一致性
核对Debug、Release等不同环境的配置文件,避免本地调试使用正确配置,但生产环境部署时加载了未更新的默认配置文件。排查触发报错的请求特征
收集偶发报错对应的请求信息:是否是特定大体积请求、包含多层嵌套结构的请求?针对性验证这类请求是否触发了某个未覆盖的配额限制。
内容的提问来源于stack exchange,提问作者Jojo

