2011-09-19 100 views
0

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

此值似乎无法重置,因为我试图以编程方式执行此操作,它甚至从计算机重新启动时停止的位置开始。

有没有办法解决这个问题?下面是其中的值设置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> 

+0

我已经成功地通过固定在过去的同时增加maxReceivedMessageSize和maxStringContentLength问题。你的报告多久了?也许你只需要让数字更大。 – phoog

回答

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" ...../>