0

在我的窗口服务中,当我从管理运行窗口服务时,ScheduledService 文件不包含“获取连接”。我认为 GetConnectionOfReportServer 有问题,可能需要更多时间。当我调试它工作正常。

代码示例

protected override void OnStart(string[] args)
        {
            TraceService("start service");
            timer = new System.Timers.Timer(1000);
            timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            timer.Interval = 90000;
            timer.Enabled = true;

        }
 protected override void OnStop()
        {
            TraceService("stopping service");
        }

 private void OnElapsedTime(object source, ElapsedEventArgs e)
        {

           time_elapsed();
            TraceService("Another entry at " + DateTime.Now);

        }
  private void time_elapsed()
        {           
            TraceService("Call susseccfully");
            GetConnectionOfReportServer();//The problem is here.
            TraceService("Get Connection");
            DailyReportFile = getReportFrmServer(reportName, param);
        }
    public void GetConnectionOfReportServer()
        {
           TraceService("I am in GetConnectionOfReportServer "); //**Edit part**

            try
            {
                NetworkCredential credential = new NetworkCredential("administrator", "epass@123");
                this.reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = credential;
                this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
                this.reportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://xxx.xxx.xxx.xxx/ReportServer");

            }
            catch (Exception ex)
            {

            }
        }
 private void TraceService(string content)
        {
            FileStream fs = new FileStream(@"c:\ScheduledService.txt", FileMode.OpenOrCreate, FileAccess.Write);

            StreamWriter sw = new StreamWriter(fs);
            sw.BaseStream.Seek(0, SeekOrigin.End);
            sw.WriteLine(content);
            sw.Flush();
            sw.Close();
        }

编辑方法

  public void GetConnectionOfReportServer()
        {
            TraceService("I am in GetConnectionOfReportServer.");
            try
            {
                TraceService("I am in Try.");
                //NetworkCredential credential = new NetworkCredential("administrator", "espl@123","");
                NetworkCredential credential = new NetworkCredential("administrator", "esmart@123");
                this.reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = credential;

                //select where the report should be generated with the report viewer control or on the report server using the SSRS service.
                this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
                this.reportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://xxx.xxx.xxx.xxx/ReportServer");
                TraceService("I am atTry end");




            }

            catch (Exception ex)
            {
                TraceService(ex.StackTrace);

            }
            finally
            {
                TraceService("I am in finally block");
            }
        }

但是当我看到我的“ScheduledService 文件”时

启动服务

通话成功

找拳

是的必须发送

是的必须发送,

我在 GetConnectionOfReportServer 中。

我在尝试。// 在这行之后应该打印“I am at Try end”

呼叫成功。

之后再次调用OnElapsedTime事件。

4

0 回答 0