我已经实现了一个工作正常的Windows窗体应用程序,之后我决定将该窗体窗体应用程序转换为Windows服务,
EventLog.WriteEntry("Before Calling Invoices1");
此行是服务的第一行,它工作正常,我可以在事件查看器中看到日志, 下一行是函数调用
bool ff = LoginLogoutAction(true);
并且此(LoginLogoutAction)函数的第一行是
EventLog.WriteEntry("inside LoginLogoutAction");
此行永远不会被执行,调用该函数后的行也永远不会被执行我已尝试捕捉到处但是代码永远不会到达捕获它只是停止,服务仍在运行并且下次服务执行时会发生同样的事情(服务每分钟执行一次)
我已将服务编辑为管理员登录但未解决问题
LoginLogoutAction函数是:
private bool LoginLogoutAction(bool bLogin)
{
EventLog.WriteEntry("inside LoginLogoutAction");
try
{
strCurrentServiceURL = "https://10.0.0.10:50000/b1s/v1/";
currentConnectionInfo.CompanyDB = "ALLAYAN";
currentConnectionInfo.UserName = "manager";
currentConnectionInfo.Password = "1234";
if (bLogin)
{
EventLog.WriteEntry("Inside if statement");
//System.Windows.Forms.MessageBox.Show("Please wait while login...");
currentOdataService.InitServiceContainer(strCurrentServiceURL);
if (!currentConnectionInfo.IsValid())
{
EventLog.WriteEntry("Inside if not valid will get out login failed");
//System.Windows.Forms.MessageBox.Show("Make sure correct user name, password and company database provided");
return false;
}
EventLog.WriteEntry("before logging in");
B1Session session = currentOdataService.LoginServer(currentConnectionInfo);
EventLog.WriteEntry("after logging in");
if (null != session)
{
//bConnected = true;
string strDisplay = currentOdataService.GetRequestHeaders() + currentOdataService.GetResponsetHeaders() + Newtonsoft.Json.JsonConvert.SerializeObject(session, Newtonsoft.Json.Formatting.Indented);
return true;
}
else
{
EventLog.WriteEntry("Session is null");
return false;
//button9.BackColor = Color.Red;
//bConnected = false;
//button9.Text = "Login";
//System.Windows.Forms.MessageBox.Show("Failed to login, please make sure server is running and the credentials are correct.");
}
}
else
{
//bConnected = false;
currentOdataService.LogoutServer();
return true;
//button9.Text = "Login";
//button9.BackColor = Color.Empty;
//System.Windows.Forms.MessageBox.Show("Logout from service successfully");
}
return true;
}
catch (Exception ex)
{
EventLog.WriteEntry("Error while logging in " + ex.Message + ex.InnerException.Message);
return false;
}
}