28

我对 WCF Web 服务的调用失败了System.Net.WebException: The request failed with HTTP status 413: Request Entity Too Large.

检查提琴手,我看到我正在发送:

内容长度:149839

超过 65KB。

在服务器上启用 WCF 跟踪,我看到:

System.ServiceModel.ProtocolException:已超出传入消息 (65536) 的最大消息大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。

添加此属性并不能解决问题。

我只尝试了该属性,并且(后来)尝试了帖子建议的其他各种属性。这是我目前拥有的(在服务器上)

<basicHttpBinding>

  <binding name="PricerServiceSoap"
    closeTimeout="00:10:00" openTimeout="00:10:00"
    receiveTimeout="00:10:00" sendTimeout="00:10:00"
    maxBufferSize="2147483647"    
    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">

    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
      maxArrayLength="2147483647" maxBytesPerRead="2147483647"
      maxNameTableCharCount="2147483647" />
  </binding>

</basicHttpBinding>

我唯一的终点(下<client>)是:

<endpoint address="/NetPricingService/Service.asmx"
  binding="basicHttpBinding" bindingConfiguration="PricerServiceSoap"
  contract="Pricing.PricerService.PricerServiceSoap"
  name="PricerServiceSoap" />

我还添加了:

<dataContractSerializer maxItemsInObjectGraph="2147483647"/>

<behavior>

我什至运行过(对于 IIS 7):

%windir%\system32\inetsrv\appcmd set config "WebServicesDev/PricingService"
-section:requestFiltering -requestLimits.maxAllowedContentLength:104857600
-commitpath:apphost

没有任何区别。

一个问题是这是一个 WCF 服务,旨在替换旧的 ASMX 服务。服务框架是使用现有 WSDL 中的 svcutil 生成的。我无法更改客户端配置(并且客户端使用多种语言)。我的测试客户端项目使用添加 Web 引用(在 下Add Service Reference / Advanced)导入了服务,因此我没有 WCF 配置。但是,如果我将测试客户端指向较旧的 ASMX 服务,它就可以工作。

我该如何解决或诊断这个问题?

附加信息

如果我使用 Microsoft 服务配置编辑器生成配置(设置 maxReceivedMessageSize 和 maxBufferSize),它可以工作。问题是端点是在 下指定的<service>,它不会让我指定 /NetPricingService/Service.asmx 相对地址。如果我在 svcutil 生成的配置(端点位于<client>)中编辑绑定,则它不适用于大请求。

4

6 回答 6

26

答案正盯着我的脸。

svcutil 生成的配置是针对客户端的。我在服务器上使用它。

我正在编辑 下指定的端点的绑定<client>,这对服务完全没有影响。

添加适当的<service>端点并在其绑定上设置 maxReceivedMessageSize 和 maxBufferSize 解决了该问题。

于 2013-02-01T23:20:22.790 回答
25

我有一个类似的问题。对我来说,问题是我的端点没有明确命名绑定使用bindingConfiguration,因此一定是在某处使用了一些默认值。

我有:

<webHttpBinding>
    <binding 
        name="myXmlHttpBinding" 
        maxReceivedMessageSize="10485760" 
        maxBufferSize="10485760">
        <readerQuotas 
            maxDepth="2147483647" 
            maxStringContentLength="2147483647" 
            maxArrayLength="2147483647" 
            maxBytesPerRead="2147483647" 
            maxNameTableCharCount="2147483647"/>
        <security mode="None"/>
    </binding>
</webHttpBinding>

我的端点定义为:

<service 
    name="blah.SomeService">
    <endpoint 
        address="" 
        behaviorConfiguration="WebHttpBehavior" 
        binding="webHttpBinding" 
        contract="blah.ISomeService">

        <identity>
            <dns value="localhost"/>
        </identity>
    </endpoint>
</service>

一旦我将端点更改为:

  <service name="blah.SomeService">
    <endpoint address="" 
        behaviorConfiguration="WebHttpBehavior" 
        binding="webHttpBinding" 
        bindingConfiguration="myXmlHttpBinding" 
        contract="blah.ISomeService">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
  </service>
于 2013-08-12T12:03:55.073 回答
6

我也遇到了这个问题,并在提琴手中意识到正在工作的最大 Content-Length 最终为 30000000。

在验证我的 WCF 配置是否正确后,我发现一篇文章建议修改 IIS 设置请求筛选。

Web 应用程序调用 WCF 服务的大文件上传失败 - 413 请求实体太大

  1. 打开 IIS 管理器
  2. 选择您的应用
  3. 选择请求过滤图标。
  4. 选择编辑功能设置...(右侧面板)
  5. 调整最大允许内容长度(字节)默认显示为 30000000

或 web.config 文件示例

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="50000000" />
    </requestFiltering>
  </security>
</system.webServer>
于 2019-08-19T19:28:56.277 回答
1

尝试了 10 个不同博客的内容,我的同事发现了。除了 basicHttpBinding 部分之外,我们还必须在其中添加一个 basicHttpsBinding 部分。我们有一个调用 wcf 的 webapi 服务。webapi 方法在调用 wcf 服务方法时捕获了实体太大错误。此更改已应用于 wcf 服务的 web.config 文件。

于 2017-11-09T19:58:50.677 回答
1

没有任何建议对我有用。MaxReceivedMessageSize解决这个问题的方法是增加System.ServiceModel.Channels.HttpTransportBindingElement

有两个不同的MaxReceivedMessageSize参数:

  • MaxReceivedMessageSize在 System.ServiceModel.Configuration 中。基本HttpBindingElement
  • MaxReceivedMessageSize在 System.ServiceModel.Channels 中。HttpTransportBindingElement

在转储文件中,我看到它由于限制而失败HttpTransportBindingElement

将此添加到我的 web.config 解决了这个问题:

<customBinding>
   <binding closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00">
      <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" useDefaultWebProxy="true" transferMode="Buffered" />
   </binding>
</customBinding>

来源:WCF 服务在上传超过 64 KB 的文件时显示 413 Request Entity Too Large 错误

于 2021-05-22T21:18:11.337 回答
0

添加这个为我解决它:

    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_Example"
 maxBufferSize="2147483647" 
maxReceivedMessageSize="2147483647">
            </binding>
        </basicHttpBinding>
    </bindings>
于 2017-11-02T12:27:57.197 回答