How to Debug a WCF Service Hosted in Windows Service

1.Open the Service1.cs file and add two more public methods in the same class, which basically calls the OnStart() and OnStop() methods internally:

      
        public void OnDebugMode_Start()
        {
            OnStart(null);
        }
        public void OnDebugMode_Stop()
        {
            OnStop();
        }

1.Open the Program.cs and modify main

        static void Main()
        {
            #if (!DEBUG)
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
			{ 
				new Service1() 
			};
            ServiceBase.Run(ServicesToRun);
            #else
            var service = new Service1();
            service.OnDebugMode_Start();
            System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            service.OnDebugMode_Stop();
            #endif
        }

source How to Debug a WCF Service Hosted in Windows Service

 
howto/wcf_windows_service.txt · Last modified: 2015/01/09 17:16 by 192.168.242.48
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki