我遇到了一个问题,需要知道是否有人遇到过。我编写了 ac# windows 服务,它调用 Web 服务 (asmx) 来执行某些功能。该服务在本地机器上部署时似乎运行良好。但是当它在远程开发测试环境(Win server 2003)中部署和运行时,它会抛出一个错误,捕获为下面的事件日志。
" 找不到源 (.NET 运行时 4.0 错误报告) 中事件 ID (5000) 的描述。本地计算机可能没有必要的注册表信息或消息 DLL 文件来显示来自远程计算机的消息。您可以使用 /AUXSOURCE= 标志来检索此描述;有关详细信息,请参阅帮助和支持。以下信息是事件的一部分:clr20r3, yllddkcpf0zkiftk0gcwtfigwkqck35d, 1.0.0.0, 50069cd9, tpplc.intranet.applications.incidentreporting.emailingservice, 1.0.0.0 , 50069cd9, d, 18a, system.nullreferenceexception, NIL。”
以下是代码片段的剥离但相关版本。
服务的启动 -</p>
protected override void OnStart(string[] args)
{
try
{
//Some initialization code
…
…
//Start the thread to notify email recipients.
emailThread = new Thread(NotifyRecipients);
emailThread.Start();
}
}
private void NotifyRecipients()
{
//Now call the web service to fetch the execution time which is actually set from the web app.
GetEmailSchedule();
while (true)
{
// Some Logic
//Send email only on the scheduled time of the day AND if the current time matches the
//email scheduled time OR if the current hour is greater than the scheduled hour.
if ((DateTime.Now.TimeOfDay >= executionTime) && (!EmailSent))
{
SendMail();// In this method call Email is sent and the EmailSent flag is set to true.
}
}
}
private void GetEmailSchedule()
{
try
{
LogModule.LogDebug("Calling WebMethod instance to get Email Schedule");
EmailService.IncidentDetails emailSchedule = new EmailService.IncidentDetails();// Place of error
emailSchedule.UseDefaultCredentials = true;
LogModule.LogDebug("Calling WebMethod to get Email Schedule");
string schedule = emailSchedule.GetEmailSchedule();
if (string.IsNullOrEmpty(schedule.Trim()))
{
//Get the default time from the app.config file to send emails to recipients.
}
else
{
//Get the individual time components
string[] scheduleSplit = schedule.Split(',');
executionHour = Convert.ToInt32(scheduleSplit[0].Trim());
executionMinute = Convert.ToInt32(scheduleSplit[1].Trim());
}
executionTime = new TimeSpan(executionHour, executionMinute, 0);
//Check if the retrieved exeuction hour or minute has changed from its last execution so that
//emailsent flag can be reset and email can be sent in the new schedule again.
if (executionHour != ExecutedHour || executionMinute != ExecutedMinute)
{
EmailSent = false;
}
}
catch (Exception ex)
{
LogModule.LogError("Error Occurred: " + ex.Message + " ; Inner Exception: " + ex.InnerException.ToString());
LogEvent("Error Occurred: " + ex.Message + " ; Inner Exception: " + ex.InnerException.ToString(), EventLogEntryType.Error);
SendExceptionMail(ex);
}
}
通过添加自定义日志进行调试后,我意识到这发生在实例化 Web 服务以调用 GetEmailSchedule() 方法中的 Web 方法时,即 EmailService.IncidentDetails emailSchedule = new EmailService.IncidentDetails();
不知道为什么会这样。任何帮助将不胜感激。