Dear All,
I'm trying to create windows service to upload data from the client machine to the server using Ajax/web-server to SQL database.
Here, the window's services will create one log file.
The file on the client's machine is encrypted, so the windows services will first decrypt and then it will upload data onto the server. And there is one communication helper to upload data from the client's machine to the server.
The services are successfully getting the file and decrypting, but not uploading the data onto the server.
What I have tried:
public string UploadOfflineResult()
{
var pathSouce = Directory.GetParent(Directory.GetParent(Environment.SystemDirectory.ToString()).ToString()).FullName;
var offlinePath = pathSouce + ConfigurationManager.AppSettings["resultFile"];
WriteToFile(offlinePath);
FileInfo _file = new FileInfo(offlinePath);
WriteToFile(_file.Exists ? "Offline result file exist" : "Offline result file does not exist");
if (_file.Exists && getPing())
{
WriteToFile("Working ON offline exam result file");
OfflineExamResult offlineExamResult = null;
try
{
FileStream fs = new FileStream(@"" + offlinePath, FileMode.Open);
WriteToFile("converted to stream file: " + @"" + offlinePath);
using (StreamReader sr = new StreamReader(fs))
{
WriteToFile("Reading file");
string data = sr.ReadToEnd();
offlineExamResult = Cryptography.Decrypt<OfflineExamResult>(data);
WriteToFile("CS: " + offlineExamResult.CandidateSessionID.ToString());
WriteToFile("Offline result file DECRYPTED");
JsonConvert.SerializeObject(offlineExamResult, Formatting.None, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
}));
WriteToFile("UpdatedOfflineCandidateExamResult: CandidateSessionID=" + offlineExamResult.CandidateSessionID + " ");
return true.ToString();
}
}
catch (Exception ex)
{
ex = ex.InnerException;
return JsonConvert.SerializeObject(
new { success = false, message = "Invalid result file content" },
Formatting.None,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
}
return false.ToString();
}
CommunicationHelper.cs
public static string UpdateCandidateOfflineExamResultUsingWindowService(string _offlineExamResult, string fullUrl)
{
WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
string postData = string.Format("offlineExamResult={0}", _offlineExamResult);
string result = Task.Run(() => webClient.UploadStringTaskAsync(fullUrl, postData)).Result;
return true.ToString();
}
Can anyone please help me.
Thanks