2010-11-25 4 views
1

내 Windows 서비스를 테스트 할 수있는 도구 또는 방법이 있습니까? Visual Studio 2010에서 제대로 작동합니다.새로 생성 된 Windows 서비스를 테스트 할 수있는 도구는 무엇입니까?

고급 설치 프로그램을 사용하여 설치 패키지 (MSI)를 만들었지 만 시작에 실패했습니다!

건배

+0

어떻게 실행 하시겠습니까? –

+0

오류를 찾으셨습니까? 그렇다면 어떤 종류입니까? – Rhapsody

+0

@Rhapsody 서비스를 설치하기 위해 고급 설치를 사용했지만 시작에 실패했습니다! –

답변

4

(나는 큰 성공을 한 적이있는) 서비스 설치를 완화도 디버깅을 용이하게하고 lubos hasko에 의해 this answer를 참조하십시오. log4net을 적용하고 대화식 모드로 콘솔에 로그하는 것을 권장합니다.

class TheService : ServiceBase 
{ 
    static void Main(string[] args) 
     { 
      if (!Environment.UserInteractive) 
      { 
       Run(new TheService()); 
      } 
      else 
      { 
       // If interactive, start up as a console app for easy debugging and/or installing/uninstalling the service 
       switch (string.Concat(args)) 
       { 
        case "/i": 
         ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location }); 
         break; 
        case "/u": 
         ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location }); 
         break; 
        default: 
         Console.WriteLine("Running service in console debug mode (use /i or /u to install or uninstall the service)"); 
         var service = new TheService(); 
         service.OnStart(null); 
         Thread.Sleep(Timeout.Infinite); 
         break; 
       } 
      } 
     } 
    } 
1

애플리케이션에 로깅이 있습니까? 이것은 아마도 그것을 고치는 방법을 확인하는 첫 번째 장소 일 것입니다. '도구'를 사용하여 '일부 Windows 서비스'를 테스트하는 것은 꽤 어렵습니다. 로깅에 대한 자세한 내용이 있고 잘못 된 것이 무엇인지 알 수없는 경우 알려 주시면 도움을 드릴 수 있습니다.

1

Windows 서비스를 직접 실행할 수 없습니다. 서비스를 설치하고 시작해야합니다.

서비스를 설치하는 것이 서비스를위한 부트 스트랩 코드를 수정하여 대화식으로 서비스로 실행되는지 여부를 감지하고 후자의 경우 Windows 양식을 표시하는 데 가치가 있습니다.

ServiceBase service = ...; 

if (Environment.UserInteractive) 
{ 
    // run as application 
    Application.EnableVisualStyles(); 
    Application.Run(new SomeForm()); // the form should call OnStart on the service 
} 
else 
{ 
    // run as service 
    ServiceBase.Run(service); 
} 
1
난 당신이 (System.Configuration.Install.Installer에서 파생 된) 서비스를 생성하고 설치하기 위해 설치 클래스를 사용하고 있으리라 믿고있어

? 그렇다면이 코드 줄을 설치 관리자 또는 OnBeforeInstall 재정의 ctr에 넣습니다. 그런 다음 디버거를 연결하고 설치 프로세스를 디버그 할 수 있습니다.

System.Diagnostics.Debugger.Break() 
관련 문제