呼叫WebService 發生MaxReceivedMessageSize 錯誤


撰寫C# 呼叫一個Web Service , 由於資料量過大,所以發生MaxReceivedMessageSize 的錯誤,

錯誤訊息如下:

已超出傳入訊息 (65536) 的訊息大小配額上限。若要增加此配額,請利用適當繫結元素上的 MaxReceivedMessageSize 屬性

解決辦法可以在App.Config中加大ReceivedMessageSize和BufferSize

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="serviceSoap1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="524288"  />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/CubeRFC/service.asmx" binding="basicHttpBinding"
                bindingConfiguration="serviceSoap1" contract="RFC.serviceSoap"
                name="serviceSoap1" />
        </client>
    </system.serviceModel>
</configuration>