You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WCF SOAP服务Postman上传>50KB文件报413请求实体过大错误

解决WCF SOAP服务上传大文件返回413 Request Entity Too Large的问题

出现这个问题的核心原因是WCF默认的消息大小限制,加上base64编码会让文件体积增加约33%,导致50KB的原始文件转码后超过了默认阈值,触发413错误。以下是针对性的解决方案:

1. 修改WCF服务端的消息大小配置

WCF默认的maxReceivedMessageSize为65536字节(64KB),而base64编码后的文件体积会膨胀,必须在服务端的web.config(或app.config)中调整绑定配置:

<system.serviceModel>
  <bindings>
    <!-- 根据你的服务使用的绑定类型调整,比如basicHttpBinding或wsHttpBinding -->
    <basicHttpBinding>
      <binding name="LargeFileBinding"
               maxReceivedMessageSize="20971520" <!-- 设置为20MB,可按需调整 -->
               maxBufferSize="20971520"
               maxBufferPoolSize="20971520">
        <readerQuotas maxStringContentLength="20971520" <!-- 适配base64字符串长度 -->
                      maxArrayLength="20971520"
                      maxBytesPerRead="4096"
                      maxNameTableCharCount="16384"
                      maxDepth="32"/>
      </binding>
    </basicHttpBinding>
  </bindings>
  <services>
    <service name="YourNamespace.YourUploadService">
      <endpoint address="" 
                binding="basicHttpBinding" 
                bindingConfiguration="LargeFileBinding" <!-- 引用上面的绑定配置 -->
                contract="YourNamespace.IYourUploadService"/>
    </service>
  </services>
</system.serviceModel>

注意:

  • 确保bindingConfiguration的名称和你定义的绑定名称一致
  • 所有大小参数的值要匹配,避免出现部分限制未放开的情况

2. 调整IIS的请求大小限制(如果服务部署在IIS上)

如果你的WCF服务部署在IIS中,还需要修改IIS的请求内容长度限制:

2.1 修改ASP.NET请求长度限制(针对传统.NET框架)

在web.config的<system.web>节点下添加:

<system.web>
  <httpRuntime maxRequestLength="20480" <!-- 单位是KB,这里设置为20MB -->
               executionTimeout="360"/> <!-- 可选,延长超时时间 -->
</system.web>

2.2 修改IIS请求过滤限制

在web.config的<system.webServer>节点下添加:

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="20971520"/> <!-- 单位是字节,20MB -->
    </requestFiltering>
  </security>
</system.webServer>

3. 验证Postman请求设置

  • 确保Postman中没有手动设置过小的Content-Length请求头,让系统自动计算即可
  • 检查base64字符串是否完整,避免复制或生成过程中出现截断

内容的提问来源于stack exchange,提问作者Shikhar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 22:54:52