我正在连接到IIS 7休息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个小时。
此外,有没有办法降低连接成本或找出连接后的操作?
我知道这是很多问题,但我是网络服务的新手。