The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

今天當試Consume 公司的Partner的 Web Services時 出現了以下的錯誤..

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

問題的起因是因為 這個”Web Service” 回應的Message 的大小時大於 65536 [預設的 大小]..
幸好..這些設定都是可以在開發端的Web.Config/App.Config 條改

Default的 Web.Config/App.Config

 <binding name="ShareChiWaiHttpBinding" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
</binding>

大家可以看到 預設的
MaxBufferSize“,  “maxBufferPoolSize” 和 “MaxReceivedMessageSize” 都是設定為 65536

maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

解決方法:
只要把”MaxBufferSize“,  “maxBufferPoolSize” 和 “MaxReceivedMessageSize” 的設定更改為更大的數值.. 如: 5242880 便可以了

E.G.

maxBufferSize="52428800" maxBufferPoolSize="52428800" maxReceivedMessageSize="52428800"

最後的Web.config/App.config 就像下面的例子

<binding name="ShareChiWaiHttpBinding" closeTimeout="00:03:00"
          openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="52428800" maxBufferPoolSize="52428800" maxReceivedMessageSize="52428800"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="52428800" maxArrayLength="52428800"
            maxBytesPerRead="52428800" maxNameTableCharCount="52428800" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
</binding>

Hope you find it useful

Leave a Reply