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

C# 远程服务器返回错误:(413)请求实体太大,c#,xml,web-services,wcf,web-config,C#,Xml,Web Services,Wcf,Web Config,请不要将此邮件作为副本删除 我正在编写一个WCF服务,它允许上传XML文件,以便将它们导入数据库。但是,当我上传超过64k默认值的文件时,我收到了上述错误 我已经通读了这里已经发布的关于这个问题的所有问题,并实施了它们,但仍然面临同样的问题 我增加了配置文件中客户端和服务器的所有绑定值,以接受2GB的最大大小 <binding name="BasicHttpBinding_BailiffServices" maxBufferSize="

请不要将此邮件作为副本删除

我正在编写一个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服务接受大文件,但迄今为止没有一个有效。


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

经过几个小时的挠头之后,我终于成功地让它工作了。我从元素和元素中删除了绑定名basichttppbinding_BailiffServices。我在MSDN网站上偶然发现了这个解决方案。希望这对其他人有所帮助。

我找到了解决方案,以避免出现“远程服务器返回意外响应: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>
我还在client 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>

这也将处理超时错误。

异常的调用堆栈在哪里?这是服务器端异常还是客户端异常?这是服务器端异常。经过几个小时的苦思冥想,我终于设法让它正常工作了。我从元素和元素中删除了绑定名basichttppbinding_BailiffServices%。我在MSDN网站上偶然发现了这个解决方案。希望这对其他人有所帮助。这没有意义-如果您删除了绑定配置,您应该会得到basicHttpBinding的默认较低值。你能链接到提供解决方案的MSDN站点吗?这帮我做到了。关键是增加服务器端和客户端的maxReceivedMessageSize。