Using Windows Service Application inside Windows forms application C# - 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.

Related

Runtime information with Microsoft.Hosting.Extensions.WindowsService

I run a web API as windows service with Microsoft.Extensions.Hosting.WindowsService.
This allows me to run it as service or as console app (if I just click the exe).
Actually pretty sweet.
But is there a way to detect how it is running (console app or windows service) at runtime?
Would be interersting to have this in the logs ...

Start exe from windows services

We have created on windows application, sometimes it is getting crashed, so it stopped from client end. Again user need to start the application manually. If we create windows service, incase the application crashes we can start from exe from service, can anyone help to start the exe from windows services

Cannot start the windows service

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

call exe from wcf service

We have a WCF service that we recently switched from self-hosting to IIS-hosted. It needs to launch an executable using Process.Start(). This works fine when it's self-hosted, but when hosted in IIS, we get the error:
TimeOutException was unhandled
void notepad()
{
System.Diagnostics.Process.Start("notepad").waitForExit();
}
Any help would be appreciated. Thanks!
when you host your WCF service in IIS, being a server, IIS requires and allows no user interaction and works also if no user is logged in; in that context there is no UI to host your notepad or other UI enabled applications, you could execute a process or other batch jobs but not render a windows UI application, because Windows Explorer is not loaded for you and there is no place to render your process's UI. So you can start processes that have no UI.

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