繁体   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