Cannot start the windows service - c#

I created a WCF library, then I wrote a WCF service which can create or open a file and writes "hello world" in that file. Then I added a new project to a Windows service. In that Windows service onstart() method I call the WCF service, then I build and installed the service using installutil. The service was installed successfully, while i am starting the service in services.msc, it shows the following error
the service on local computer started and then stopped some services
stopped automatically. if they have no work to do, for example the
performance logs, and alerts.
Why am i getting this error, how can I resolve it?

(i)Clear the Application Log.
(ii)Use the debugger and trace the execution of the OnStart() method.
if these does not work,
1) Click Run Command from start button
2) Enter Services.msc then click OK,you will get all the services in your computer.
3) Select your service and right click on the service and select Properties
4) Goto Logon Properties a select Local System Account then click OK

Related

Using Windows Service Application inside Windows forms application C#

I've created a simple socket application in which I have to open a socket receiver to listen for incoming messages on desktop. Problem is I need to be able to run the application as background service and I need to be able to start and stop the service from System Tray icon, for that I've created a windows forms application and added and I've created a windows service inside a windows forms application. On debug mode when I call the service code directly It's working fine. The service is installing and the OnStart method is being called. But when I try to start the application after building the project and running the .exe file I get the following error.
"Cannot start service from the command line or a debugger a windows service must first be installed. Then start with the server explorer"
And when I try to start the service manually from the windows services panel I get the following error.
"Error 1053: The service did not respond to the start or control request in a timely fashion".
This is the code used to install the service which is working fine.
AssemblyInstaller installer = GetInstaller(assembly)
installer.Install(state);
installer.Commit(state);
And this is the code for starting the service which is giving the error.
"Cannot start service from the command line or a debugger a windows service must first be installed. Then start with the server explorer"
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SocketService()
};
ServiceBase.Run(ServicesToRun);
Can anyone please help me with this. I need to create a single msi installation utility of the entire application. In which I need to install both the desktop application and the windows service. Where the desktop application can Start or Stop the service. Thanks.

Need to debug my Web API service that's requested from a client machine - need help, how do I do this?

I built a Web API service that's hosted locally on my machine in IIS. I have an iOS app that I'm running via XCode that makes the call to the web service. The connectivity is there, and works. The iOS app successfully makes the connection to my published web service.
The problem is my web service is returning a non descriptive error to the client (iOS), so what I need to be able to do is step through the web service code while running my iOS app.
So, in summary:
I run an iOS app via my MacBook, and it connects to my .NET Web API service.
My Web API service is published to my local IIS, and is returning an error back to the client.
Breakpoints aren't being hit in Visual Studio - do I need to attach my Visual Studio debugger to a specific process? I've tried running my web service in debug mode while running my iOS app, to no avail.
How can I step through my web service code when running the client app (iOS) that accesses the web service?
Attach to process - http://msdn.microsoft.com/en-us/library/vstudio/3s68z0b3.aspx
Make sure "Show processes from all users" is checked, and pick w3wp.exe
You may need to hit the service once first to make sure its started.
To debug an app that's hosted by IIS, you want to attach to process (in Visual Studio it's Tools->Attach to Process or Ctrl+Alt+P) and pick w3wp.exe from the list (you might have to check a few boxes for the process to show up).
Another option is to use our free VS Extension called Conveyor
https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti
With it you open up IIS Express to remote connections on your network (or even the web through tunnelling).
Once you've done that you can debug the project directly from VS and connect to the Conveyor port number (or domain name via tunnelling) and debug as you would locally.
you can use Postman client.
First : run the API FROM visual studio
Second : go to postman put the url and add the parameter in body
More information : http://www.tutorialsteacher.com/webapi/test-web-api
this often works for me i generally list all of the processes in IIS with appcmd command
appcmd list wp
and pretty much you know which process to attach by seeing the names of the web services
if appcmd is not available please visit
Here for configuring this

why does my service says it's running even though it's not?

I created a service using .NET that is supposed to start automatically and run as a User with my username & password.
If I restart my PC, log on with the same username & password, and go to Task Manager, it says that the service is running, but when I check the Event Log there are no messages stating that the service has started, and in fact, the service has not started, because it doesn't do what it's supposed to be doing.
On the other hand, if I manually stop and start the service, then the entries in the Event Log appear and the service runs as it's supposed to.
So when I restart my PC, how come Task Manager says that the service is running even though it's not running? Is there a security setting that I need to tweak?
Does your service have a dependency on another Windows service? If so then it may be that your service is failing to initialize correctly when the machine restarts as it can't make use of the functionality in needs from the dependent service.
This would explain why if you restart the service is works correct.
I was able to solve the problem: the service was failing to initialize properly on windows restart because it was not dependent on any service, when it should have been dependent on the event log service. Setting the "ServicesDependedOn" property of the ServiceInstaller object to "Windows Event Log" solved the problem. Thanks for the help!

Remote LogOn with WCF and C#

Is there any way to log on to a Windows machine using WCF and C#? I am creating a Test Harness and it will needed to remotely logon a Windows user.
So far we have not been able to do it successfully as once the user has been log off from the machine, self-hosted WCF is shut down.
your problem is that you are hosting the service as a console app. When the user logs off, the app stops.
Host your service in a windows service, which will enable it to start and run without a user being logged on.
MSDN on hosting in a windows service
as a tip, in the OnStart method add the following line:
Debugger.Launch();
and a using statement:
using System.Diagnostics;
if you have problems with the service starting and immediately stopping. This should allow you to attach a debugger to the service as it is starting to debug the issue.
Using supplied credentials on the web end you could try logging in via WMI? but, it does depend what you intend to do to the remote machines - other option would be a client on the remote machines

windows service cannot stop

Created a simple WCF service that basically logs to a db.
the build is fine and created a msi install file for it.
I installed the windows service and start it which works, however when i stop it i get this error:
"Could not stop the service1 service
on local computer. The service did not
return an error. This could be an
internal windows error or an internal
service error. If the problem
persists, contact your system
administrator."
There are a couple of ways to diagnose this:
If you haven't already, separate out the implementation of the windows service from the actual service executable. That way you can run / debug the code from a console or forms app easily.
If that doesn't reveal any answers, add verbose logging to the shutdown method to find out what is happening.

Categories