在客户端传输大量的数据到WCF服务端时,由于数据包过大,会导致"Maximum request length exceeded."异常。
首先,应当检查程序是否存在将不必要的数据传输到服务器,并进行适当优化,在不可避免时,可通过配置web.config调大阀值。
在system.web段中添加httpRuntime配置项,如下面的代码所示:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="51200"/>
</system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="51200"/>
</system.web>