WCF 服务“远程服务器返回错误: (413) 请求实体太大

本文关键字:请求 实体 错误 服务 返回 服务器 WCF | 更新日期: 2023-09-27 18:36:22

我正在处理使用 wsHTTPBinding 的 WCF 服务,当我在某个时候使用我的客户端测试应用程序进行调用时,我收到错误 远程服务器返回了意外的响应:The remote server returned an error: (413) Request Entity Too Large.

我的 web.config 中对该服务的绑定配置如下所示:

        <wsHttpBinding>
            <binding name="secureHttpBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"/>
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" />
                </security>
            </binding>
        </wsHttpBinding>

服务端的端点:

        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="WS_UCC_XML.IWS_UCC_XML" />

以及客户端中的绑定配置:

        <wsHttpBinding>
            <binding name="wsHttpBinding_IWS_UCC_XML_SSL" maxBufferPoolSize="2147483647"
                maxReceivedMessageSize="2147483647"  receiveTimeout="01:00:00" sendTimeout="01:00:00">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
                <security mode="Transport">
                    <transport clientCredentialType="Certificate" />
                </security>
            </binding>
        </wsHttpBinding>

WCF 服务“远程服务器返回错误: (413) 请求实体太大

将 maxBufferSize="2147483647" 参数添加到 config 中的客户端和服务器绑定标记中:

<binding name="secureHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">

还可以尝试MaxItemsInObjectGraph - 将以下内容添加到服务器和客户端的"system.serviceModel"部分:

<commonBehaviors>
  <endpointBehaviors>
    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
  </endpointBehaviors>
  <serviceBehaviors>
     <dataContractSerializer maxItemsInObjectGraph="2147483647" />
  </serviceBehaviors>
</commonBehaviors>