2015年4月22日 星期三

Troubleshooting - WCF error (413) Request Entity Too Large

.NET    WCF

背景

先前在某電信結案的程式碼,出現了 (413) Request Entity Too Large的錯誤訊息,
原來是WCF預設單筆Message size 65KB 避免DDOS攻擊。
當超過此上限時,便會引發此錯誤。

環境

l   Windows 7 pro
l   MS Sql Server 2012
l   Visual Studio 2013 updat4 (C#)

解決方式


Server Side

Config檔加入以下設定
<configuration>
<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding maxReceivedMessageSize="2147483647"
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="32"
                        maxArrayLength="2147483647"
                        maxStringContentLength="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>
</system.serviceModel>
</configuration>



Client Side

<configuration>
<system.serviceModel>

      <bindings>
          <basicHttpBinding>
              <binding name="BasicHttpBinding_IMonitorService"
                        maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" receiveTimeout="00:30:00" sendTimeout="00:30:00"/>
          </basicHttpBinding>
          <netNamedPipeBinding>
              <binding name="NetNamedPipeBinding_IMonitorService">
                  <security mode="None" />
              </binding>
          </netNamedPipeBinding>
       
      </bindings>
</system.serviceModel>
</configuration>



Reference




沒有留言:

張貼留言