Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created a windows service my WCF and when i stop the the service and i run the application it is not throwing any error.When i debug it dint even hit onstart method of windows service.

C#
protected override void OnStart(string[] args)
       {
           System.Diagnostics.Debugger.Launch();
           if (myServiceHost != null)
           {
               myServiceHost.Close();
           }
           myServiceHost = new ServiceHost(typeof(Service1));
           myServiceHost.Open();
       }


How can i debug the onstart() method?
Posted

1 solution

Apparently, if you show some method which is never called (called, not "hit"), and nothing except this method, you don't show the code where your problem is. The problem is always outside this method. Isn't this obvious?

Besides, I cannot be 100% sure that your conclusion that the method is never called. Debugging of a Windows Service is not such a trivial thing. I'm not even sure you attempted to start the Service correctly. It cannot be started as a regular application. It won't behave like a Service unless it is started by a Service Controlled, which is a special application host.

So, you should get one of the basic principles, and this is all, based on the information you provided. From this point, you can start your investigation. Here is a hint for you: if this method is not called, you did not even start developing a Windows Service. Please see:
http://msdn.microsoft.com/en-us/library/y817hyb6.aspx[^],
http://msdn.microsoft.com/en-us/library/zt39148a.aspx[^].

—SA
 
Share this answer
 
Comments
shacha 27-Aug-13 1:00am    
But the thing is even though i have stopped the service the application is running, but i should get some error right?

I have created a service and installed it in the services and it is running.
Sergey Alexandrovich Kryukov 27-Aug-13 1:00am    
No, why?
—SA
shacha 27-Aug-13 1:05am    
Even though if i run the application when the service is stopped then what is the use of hosting a service using WAS?
Sergey Alexandrovich Kryukov 27-Aug-13 1:19am    
Here:
Sergey Alexandrovich Kryukov 27-Aug-13 1:19am    
Here:
http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx.

I have no idea why do you use it in this method. :-)

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900