c# – (413)请求实体太大



<?xml version="1.0" encoding="utf-8"?>
                <binding name="BasicHttpBinding_IMyService" sendTimeout="00:05:00"
                    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />


正如Matt Burland建议的那样,您需要配置服务端和客户端.有关详情,请参见Configuring Services Using Configuration Files.任务与您在电线的客户端所做的工作没有太大的不同.这是上述文章的摘录.

WCF uses the System.Configuration configuration system of the .NET
Framework. When configuring a service in Visual Studio, use either a
Web.config file or an App.config file to specify the settings. The
choice of the configuration file name is determined by the hosting
environment you choose for the service. If you are using IIS to host
your service, use a Web.config file. If you are using any other
hosting environment, use an App.config file.

我建议不要将所有内容设置为int.MaxValue,因为将MaxReceivedMessageSize设置为2GB会打开DOS(拒绝服务)攻击等. MaxReceivedMessageSize属性的备注部分甚至指出:

The size of the messages that can be received on the wire by services
using the WSHttpBindingBase is bounded by the amount of memory
allocated for each message. This bound on message size is intended to
limit exposure to denial of service (DoS) attacks.


转载注明原文:c# – (413)请求实体太大 - 代码日志