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

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

请不要将此消息作为重复消息删除!!

我正在编写一个WCF服务,它允许上传XML文件,以便将它们导入数据库。然而,当我上传一个超过64k默认值的文件时,我收到了上述错误。

我已经阅读了这里已经发布的关于这个问题的所有问题,并实施了这些问题,但仍然面临着同样的问题。

我已经增加了配置文件中的所有绑定值(对于客户端和服务器),以接受2GB的最大大小。


    <binding name="BasicHttpBinding_BailiffServices"
                     maxBufferSize="2147483647"
                     maxBufferPoolSize="2147483647"
                     maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647" 
                            maxStringContentLength="2147483647"
                            maxArrayLength="2147483647" 
                            maxBytesPerRead="2147483647"
                            maxNameTableCharCount="2147483647" />
              <security mode="None" />

以下是使用此绑定的WCF服务。


    <services>
          <service name="ClientService.ClientService">
            <endpoint address="http://subversion/BusinessTier.Services.ClientService.svc"
              binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_BailiffServices"
              name="BasicHttpBinding_IClient" contract="ClientService.IClient" />
          </service>
          <service name="DebtorService.DebtorService">
            <endpoint address="http://subversion/BusinessTier.Services.DebtorService.svc"
              binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_BailiffServices"
              name="BasicHttpBinding_IDebtor" contract="DebtorService.IDebtor" />
          </service>
        </services>

我还在配置中添加了设置,以确保IIS也能够处理大文件。


    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <security>
          <requestFiltering allowDoubleEscaping="true">
            <requestLimits maxAllowedContentLength="2147483647"/>
            <fileExtensions allowUnlisted="true"/>
            <verbs allowUnlisted="true"/>
          </requestFiltering>
        </security>
      </system.webServer>

据我所见,我已经修改了所有必要的设置,以允许我的WCF服务接受大文件,但到目前为止,这些设置都不起作用。

如有任何建议,我们将不胜感激。

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

我找到了避免类似"远程服务器返回意外响应:(413)请求实体太大"之类错误的解决方案。"在WCF服务配置中使用basicHttpBinding时,您只需要增加Web.config中的最大消息长度。通过以下方式,您可以更新服务器Web.config和客户端app.config文件,以便通过WCF发送大字节数组。

在Web.config 中包括以下绑定和行为参数

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding maxReceivedMessageSize="2147483647" sendTimeout="00:10:00" receiveTimeout="00:10:00">
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"/>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false">
  <serviceActivations>
    <add factory ="WebService.NInjectServiceHostFactory" relativeAddress="TestServic.svc" service="WebService.Services.ServiceManager"/>
  </serviceActivations>
</serviceHostingEnvironment>

我还在客户端app.config文件中添加了绑定配置。

<system.serviceModel>
<bindings>
<basicHttpBinding>
  <binding name="BasicHttpBinding_IServiceManager"  maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
    <security mode="None"/>
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
  </binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49359/ServiceManager.svc"
 binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPackageManager"
 contract="PackageManager.IPackageManager" name="BasicHttpBinding_IPackageManager" />
</client>
</system.serviceModel>

这也将处理超时错误。

经过几个小时的努力,我终于做到了。我从<绑定/>元素和<端点/>元素。我在MSDN网站上偶然发现了这个解决方案。希望这能帮助其他人。