簡體   English   中英

WCF通信中的消息過大

[英]Message oversized on WCF communication

我有一個Windows服務和一個Winform應用程序,它們通過WCF通過TCP相互通信。

有時我必須交換大量數據,並且在客戶端遇到了CommunicationException 現在,我很難找到要更改的屬性以及更改的位置(在服務器端還是客戶端?)。

當服務器向客戶端返回一個值為兩個雙精度數組的2-uple (我自己的實現)的值時,會發生問題: Tuple<Double[], Double[]> (兩個數組的長度始終相同)。
我已經注意到,不存在錯誤時,所述陣列具有的長度22 000 ,但CommunicationException當陣列具有的長度被拋出44 000

這是關於netTcpBinding部分的App.config文件:

  • 在服務器上:

<netTcpBinding>
    <binding name="MyBindingConf"
             maxReceivedMessageSize="5000000"
             sendTimeout="00:05:00">
        <readerQuotas maxArrayLength="67108864"
                      maxStringContentLength="67108864"/>
        <security mode="None" />
    </binding>
</netTcpBinding>
  • 在客戶端上:

<netTcpBinding>
    <binding name="MyBindingConf"
             maxReceivedMessageSize="5000000"
             sendTimeout="00:59:00">
        <readerQuotas maxArrayLength="67108864"
                      maxStringContentLength="67108864"/>
        <security mode="None" />
    </binding>
</netTcpBinding>

您能否指出要更改的屬性以及在哪一邊?

PS:這不是超時問題。


編輯

我現在在服務器和客戶端上都具有相同的nettcpbinding配置:

<bindings>
    <netTcpBinding>
        <binding name="MyBindingConf" 
                 maxReceivedMessageSize="2147483647" 
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 sendTimeout="00:30:00">
            <readerQuotas maxDepth="32" 
                          maxStringContentLength="2147483647" 
                          maxArrayLength="2147483647" 
                          maxBytesPerRead="4096" 
                          maxNameTableCharCount="16384" />
            <security mode="None" />
        </binding>
    </netTcpBinding>
</bindings>

和相同的serviceBehavior

<behaviors>
    <serviceBehaviors>
        <behavior name="Debug">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
    </serviceBehaviors>
</behaviors>

然后,我在客戶端上收到NetDispatcherFaultException ,建議我增加maxArrayLengthmaxItemsInObjectGraph 但是對我來說,這些值已經為我需要傳輸的內容進行了很大的設置,並且還設置為最大值!

這是InnerException消息:

讀取XML數據時,已超出最大數組長度配額(19502)或對象圖配額中的最大項目。 通過更改XmlDictionaryReaderQuotas或MaxItemsInObjectGraph設置上的MaxArrayLength屬性,可以增加這些配額。

有什么線索嗎? 這個19 502數字來自哪里?

在服務器和客戶端上,如果要在它們之間交換大量數據,則必須配置它們的屬性。 例如:

<binding name="LargeSettings" maxBufferSize="20000000" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
      <readerQuotas maxDepth="32" maxStringContentLength="200000000" maxArrayLength="200000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None" />
    </binding>

從大的價值中找到適合自己的價值。

編輯:

在客戶端,您需要配置一個行為,並在客戶端端點中設置該行為。 像這樣:

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="debug"> <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
        </endpointBehaviors>
    </behaviors>

然后在客戶端端點中設置行為:

<endpoint name="myEndpoint" behaviorConfiguration="debug">
    Your other settings...
</endpoint>

希望這可以幫助。

我個人將增加MaxReceivedMessageSize ,確保同時調整maxBufferSize 這些是我們需要調整的常見領域。

這是我在測試中使用過的wsHttpBinding的副本,可以成功傳輸大量數據。 我並不是說這些值是最佳做法,但它們可以傳遞大量數據。

    <binding name="WSHttpBinding_LargeData" 
      maxBufferPoolSize="524288" 
      maxReceivedMessageSize="99999999">

      <readerQuotas 
         maxDepth="128" 
         maxStringContentLength="8192" 
         maxArrayLength="163840000" 
         maxBytesPerRead="4096" 
         maxNameTableCharCount="16384"
      />
    </binding>

您是否在服務行為中嘗試過maxItemsInObjectGraph

 <dataContractSerializer maxItemsInObjectGraph="2147483647"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM