我遇到了一個問題,需要知道是否有人遇到它。我寫了一個調用Web服務(asmx)來執行某些功能的c#windows服務。 該服務在本地計算機上部署時似乎工作正常。但是,當它在遠程開發測試環境(Win server 2003)中部署和運行時,它將引發下面捕獲的事件日誌錯誤。在啓動Windows服務中拋出源(.NET運行時4.0錯誤報告)中的事件ID(5000)錯誤
「 無法找到源(.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。 「
以下是代碼片段的剝離但相關版本。
服務的的OnStart -
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服務實例來調用Web方法中是 EmailService的GetEmailSchedule()方法的時刻.IncidentDetails emailSchedule = new EmailService.IncidentDetails();
不知道爲什麼會發生。任何援助將不勝感激。