因此,我通过生物识别技术为Php创建了Windows Service API。每次我通过Web客户端发送数据时,它都会发送重复数据,而不是仅发送1个数据,例如:
Web服务->发送-> 1.Cardo Dalisay 01/01/2018 1:01:10 PM-> 1.Cardo Dalisay 01/01/2018 1:01:10 PM
//Get Data from biometric
ICollection<MachineInfo> lstmachineInfo = manipulator.GetLogData(objZkeeper, int.Parse(MachineNo));
//if its not null
if (lstmachineInfo != null && lstmachineInfo.Count > 0)
{
//new list for new updated data
List<MachineInfo.Datasend>zkteco = new List<MachineInfo.Datasend>();
const string encryptionkey = @"ZREpfb7s2q0+Jq598jTlGTSHovHMJ1ok";
//lambda which fetch only new data
var result = lstmachineInfo.ToList().Where(a => a.datetime >= DateTime.Now.AddMinutes(-1)).ToList();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//webclient is here
using (var webclient = new WebClient())
{
//fetch the newly data
foreach (var data in result)
{
//store then to new list
zkteco.Add(new MachineInfo.Datasend
{
_machineNumber = data.MachineNumber,
_subscription = Subscription,
_branchid = BranchID,
_userid = data.UserID,
_DateTimeRecord = data.DateTimeRecord,
_Checktype = data.InOut,
_Accesstoken = AccessToken
});
string JsonResponse = JsonConvert.SerializeObject(zkteco);
}
//fetch the newly stored data
foreach (var zktecolist in zkteco)
{
//namevaluecollection for webclient
var values = new NameValueCollection();
values["machineid"] = zktecolist._machineNumber.ToString();
values["subscription"] = zktecolist._subscription.ToString();
values["branchid"] = zktecolist._branchid.ToString();
values["userid"] = zktecolist._userid.ToString();
values["datetime"] = zktecolist._DateTimeRecord;
values["checktype"] = zktecolist._Checktype.ToString();
values["accesstoken"] = zktecolist._Accesstoken.ToString();
//请求跟随 //以下是webclient请求
var request = webclient.UploadValues("http://192.168.1.119/api/biometric_activity?data", values);
var response = Encoding.UTF8.GetString(request);
var apiResponse = JsonConvert.DeserializeObject<ApiResponse>(response);
if (apiResponse.status == "Ok")
{
WriteToFile("test" + apiResponse.description + " -> " + apiResponse.message + "status -> " + apiResponse.status);
}
else if (apiResponse.status != "Ok")
{
WriteToFile("No Data has been fetch");
}
}
}
}
else
{
objZkeeper = new ZkemClient(RaiseDeviceEvent);
isDeviceConnected = objZkeeper.Connect_Net(IPAddress, Port);
WriteToFile("failed in connecting with device, reconnecting ....");
}
}