Error消息:
System.Net.WebException: The remote server returned an error: (413) Request Entity Too Large.
解决办法
修改请求端的配置文件,单位是KB,在<system.web></system.web>:
<httpRuntime executionTimeout="600" maxRequestLength="20480" />
maxRequestLength=20480表示最大上传文件的大小限制在20M以内。
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IDEMOFrontendService" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text"> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost/DEMOFrontend/DEMOFrontendService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDEMOFrontendService" contract="DEMOFrontendServiceReference.IDEMOFrontendService" name="BasicHttpBinding_IDEMOFrontendService" /> </client> </system.serviceModel>
修改WCF配置文件,在<system.serviceModel></system.serviceModel>:
<bindings> <basicHttpBinding> <binding name="DemoHttpBinding_CheckAccess" closeTimeout="00:50:00" openTimeout="00:50:00" receiveTimeout="00:50:00" sendTimeout="00:50:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" > <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> <message clientCredentialType="UserName" algorithmSuite="Default"/> </security> </binding> </basicHttpBinding> <basicHttpsBinding> <binding name="DEMOHttpsBinding_GetwayService" closeTimeout="00:50:00" openTimeout="00:50:00" receiveTimeout="00:50:00" sendTimeout="00:50:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" > <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> <security mode="Transport"> <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> <message clientCredentialType="UserName" algorithmSuite="Default"/> </security> </binding> </basicHttpsBinding> </bindings>
<protocolMapping> <add binding ="basicHttpsBinding" scheme="https" bindingConfiguration="DEMOHttpsBinding_GetwayService" /> <add binding ="basicHttpBinding" scheme="http" bindingConfiguration="DemoHttpBinding_CheckAccess"/> </protocolMapping>
参考