【问题标题】:c# - The remote server returned an unexpected response: (413) Request Entity Too Largec# - 远程服务器返回意外响应:(413)请求实体太大
【发布时间】:2018-03-23 12:40:44
【问题描述】:

我正在尝试创建一个 Windows 应用程序,它将定期捕获屏幕并将图像转换为二进制文件并通过 WCF 服务发送。 WCF 将此值保存在 SQL 数据库中。

我无法通过 WCF 服务发送它引发错误。 除了二进制图像,我只发送用户名。

我检查了总服务大小约为 200kb,也在 web.config 文件中我给出了 maxReceivedMessageSize="2000000"(2MB) 的允许大小。

<bindings>
        <basicHttpBinding>
            <binding name="sslBinding" maxReceivedMessageSize="2000000" maxBufferSize="2000000">
                <readerQuotas maxArrayLength="2000000" maxStringContentLength="2000000" />
                <security mode="Transport" >
                  <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>

试过了:

  • 删除了绑定名称
  • 竟然给maxReceivedMessageSize是5MB。

我不想将 basicHttpBinding 更改为 webHttpBinding,因为其他服务正在同一个应用程序中运行。

我已经提到了3089022044234761的问题

【问题讨论】:

  • 您的数据有多大?如果它是原始屏幕截图,则它可能大于 5mb。在尝试通过网络发送之前,您应该将其转换为 JPG 或 PNG,并可能在发送之前对其进行压缩。
  • @RonBeyer,我尝试保存这个文件,它只有 180 KB,还以 90% 的质量压缩了这个图像,即使我尝试了 75% 的质量。
  • 您的客户端配置是什么样的?是一样的吗?
  • 是的,maxReceivedMessageSize="2000000"

标签: c# web-services wcf


【解决方案1】:

尝试将其用于您的绑定:

      <basicHttpBinding>
    <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>

我知道你已经修改了 maxReceivedMessageSize,所以上面你也篡改了 readerQuotas。

您也可以尝试在 IIS 中增加 uploadReadAheadSize:

<location path="THENAMEOFTHESITEYOUHAVE" overrideMode="Allow">
<system.webServer>
    <asp />
    <serverRuntime uploadReadAheadSize="2147483647" />
</system.webServer>

【讨论】:

    猜你喜欢
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    • 1970-01-01
    相关资源
    最近更新 更多