1

我在我的项目中使用 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>
4

1 回答 1

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>
于 2012-04-17T22:18:46.527 回答