了解MaxReceivedMessageSize限制

时间:2011-09-19 16:22:24

标签: c# .net iis

我正在编写一个控制台应用程序,每天通过API从外部服务器下载报告。我遇到了MaxReceivedMessageSize大小限制的问题,因为我总是超过那里设置的值(在app.config中)。

这个值似乎无法重置,因为我已经尝试以编程方式进行,并且它甚至从计算机重启时停止的位置开始。

有没有办法解决这个问题?下面是app.config文件,其中设置了值:

<binding name="ReportingSoap" closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="64000" maxBufferPoolSize="524288" maxReceivedMessageSize="1000000" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
    <readerQuotas maxDepth="64" maxStringContentLength="2000000" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
        <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
        </security>

<binding name="ReportingSoap" closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="64000" maxBufferPoolSize="524288" maxReceivedMessageSize="1000000" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true"> <readerQuotas maxDepth="64" maxStringContentLength="2000000" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> <message clientCredentialType="UserName" algorithmSuite="Default"/> </security>

1 个答案:

答案 0 :(得分:0)

在服务器端,将serviceBehaviours定义为:

<serviceBehaviours>
      <behavior name="servicebehaviour">
           <dataContractSerializer maxItemsInObjectGraph="655360000" />
      </behavior>
</serviceBehaviours>

并在服务标签中使用它:

<service behaviorConfiguration="servicebehaviour"  ....>

同样,在客户端,您必须将endpointBehaviors定义为:

<endpointBehaviors>
      <behavior name="custombehaviour">
           <dataContractSerializer maxItemsInObjectGraph="655360000" />
      </behavior>
</endpointBehaviors>

并在endpoint

中使用此功能
<endpoint behaviorConfiguration="custombehaviour" ...../>