2012-04-17 74 views
1

我在我的項目中使用WCF從服務器(訪問數據庫)和客戶端傳輸數據,該客戶端在屏幕上繪製數據。大量數據通過WCF傳輸

傳輸的數據量非常大,所以我想知道哪個是最好的方式。

現在,我能夠查詢少量數據,大約3600個對象(時間戳和雙精度值)。但是,如果此數字增加到大約86400個對象,則會發生服務函數調用中的錯誤。

我的服務端和客戶端的聲明如下:

服務器:

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata/> 
      <dataContractSerializer maxItemsInObjectGraph="6553600"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="serviceName"> 
     <endpoint binding="netTcpBinding" contract="interfaceName"> 
      <identity> 
      <dns value="localhost"/> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:5050/msservice"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 

客戶:

<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="NetTcpBinding_IService" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxConnections="10" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/> 
      <security mode="Transport"> 
      <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/> 
      <message clientCredentialType="Windows"/> 
      </security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <client> 
     <endpoint address="net.tcp://localhost:5050/msservice" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService" contract="IService" name="NetTcpBinding_IService"> 
     <identity> 
      <dns value="localhost"/> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
+0

你看過流媒體嗎? [大數據和流式傳輸](http://msdn.microsoft.com/zh-cn/library/ms733742.aspx) – Tim 2012-04-18 00:58:20

回答

1

您在.NET 4?如果不是,我相信您需要提供服務行爲的名稱並將其與服務關聯。

編輯:否則,可以使用默認的maxItemsInObjectGraph值65536。

<system.serviceModel> 
<services> 
    <service name="YOURPROJECT.Web.YOURSERVICE" 
      behaviorConfiguration="YOURPROJECT-Web-YOURSERVICE"> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
     <behavior name="YOURPROJECT-Web-YOURSERVICE"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <dataContractSerializer maxItemsInObjectGraph="6553600"/> 
     </behavior> 
    </serviceBehaviors> 
</behaviors> 
+0

請注意maxItemsInObjectGraph屬性,因爲這是OP正在查找的內容。 – Chris 2012-04-17 22:21:13

+0

我做了,它的設置高於應該導致錯誤的設置。 6553600> 86400.默認值爲65536.似乎較大的值無法識別。也許是由於行爲。 – richk 2012-04-17 22:24:56

+0

最大值是2147483647. – richk 2012-04-17 22:26:22