0

我正在连接到 IIS 7 rest web 服务器并发送 gps 读数。我们每 20 秒保存一次读数,但每 60 秒将其提交到 Web 服务。

这是我的连接:

    var readings = Reading.GetUnProcessReadings().ToList();

    var gpsreadings = new List<TruckGpsReading>();

    history.History = "TruckGpsReading count: " + readings.Count();

    var count = 1;
    while (readings.Any())
    {
      {
        gpsreadings = new List<TruckGpsReading>();
        if (readings.Any())
        {
          history.History = "No. Transactions to process: " + count;
          foreach (var reading in readings)
          {
            history.History = "Currently reading #" + count;
            history.History = "Processing reading: " + reading.DateTimeOfReading;
            Logging.Log("Starting ProcessGpsFile.ProcessReading 3", "ProcessReading", Apps.RemoteTruckService);
            var gpsreading = new TruckGpsReading();
            gpsreading.DateTimeOfReading = reading.DateTimeOfReading;
            gpsreading.Direction = reading.Direction;
            gpsreading.DriverNumber = CurrentIniSettings.DriverNumber;
            gpsreading.GpsReadingId = reading.ReadingId;
            gpsreading.Latitude = (float) reading.Latitude;
            gpsreading.Longitude = (float) reading.Longitude;
            gpsreading.Speed = reading.Speed;                
            gpsreading.TruckNumber = string.IsNullOrWhiteSpace(CurrentIniSettings.TruckNumber) ? "99" : CurrentIniSettings.TruckNumber;
            gpsreadings.Add(gpsreading);
            TotalReadings++;
            count++;
          }

          var response = client.SaveGpsReadings(globalSetting.TokenId, globalSetting.SourceId, gpsreadings.ToArray());
          if (response != "true")
          {
            history.History = "Transactions NOT saved: " + response;
            Logging.Log("ProcessGpsFile.ProcessReading: " + response, "ProcessReading", Apps.RemoteTruckService);
          }
          else
          {
            history.History = "Transactions saved.";
            Logging.Log("ProcessGpsFile.ProcessReading: Reading.DeleteGpsReadings(readings)", "ProcessReading",
                        Apps.RemoteTruckService);
            Reading.DeleteGpsReadings(readings);
          }
        }

这是 TruckGpsReading:

  [DataContract]
  public class TruckGpsReading
  {
    [DataMember]
    public string DriverNumber { get; set; }

    [DataMember]
    public string TruckNumber { get; set; }

    [DataMember]
    public float Latitude { get; set; }

    [DataMember]
    public float Longitude { get; set; }

    [DataMember]
    public DateTime DateTimeOfReading { get; set; }

    [DataMember]
    public int Speed { get; set; }

    [DataMember]
    public string Direction { get; set; }

    [DataMember]
    public int OdometerReading { get; set; }

    [DataMember]
    public Guid GpsReadingId { get; set; } 

  }

我发现每条记录发送的信息量约为 256 个字节,但似乎连接在 30k 区域内。我不确定是什么原因造成的,或者是否有更好的解决方法。

我的问题是当数据发送时,它是通过蜂窝网络传输的。这些网络的每月数据使用量受到限制,我正试图将这种使用量降至最低。

如果我要在我的应用程序打开并保持连接时连接服务,这是一个坏主意吗?我在想我们可以在应用程序启动时连接,并且有 1 次连接成本,而不是每次发送时都连接。编辑我想补充一点,这个程序每天运行大约 8 到 10 个小时。

此外,有没有办法降低连接成本或找出连接时在做什么?

我知道这是很多问题,但我是 Web 服务的新手。

4

0 回答 0