2011-09-19 162 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" ...../>