我正在编写一个控制台应用程序,每天通过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>
答案 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" ...../>