Windows service fails to start - c#

I'm trying to get my head around WCF applications hosted as a Windows service but I'm not sure what's happening here.
Basically, to get started, I've got a literal copy and paste of the code in this article: (I know, I shouldn't)
https://msdn.microsoft.com/en-us/library/vstudio/ms733069%28v=vs.110%29.aspx
The service builds fine and I can install it without issue. It shows up in services.msc also. I'm installing it as follows: (from the visual studio command prompt)
installutil Service.exe
However when it runs, I get the following error:
The WCFWindowsServiceSample service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
What am I doing wrong?

Related

Access Denied. installutil.exe installation after rebuilding in VS Express 2013

This is my first time in C#, and I was following this tutorial in order to test out a Directory Monitoring Service. The relevant installation steps is in Step 6:
http://www.rhyous.com/2012/11/27/c-creating-a-service-to-monitor-a-directory/
Step 6 – Install the Service
Open the Developer Command Prompt by right-clicking and choosing Run as
Administrator.
In the command prompt, change to the bin\debug folder in your project
directory.
Run this command to install the service:
installutil.exe DirectoryMonitoring.exe
Start the service with this command.
net start DirectoryMonitoringService
After following the tutorial, my service was able to install and run after building using the Visual Studio Development Console. I then updated my code a little and built it again.
I tried using the same steps to install or run the service via the VSD console again, but I get an Accessed Denied error when I try to do either commands.
I get the following error for the installation:
System.InvalidOperationException: Cannot open Service Control Manager on
computer '.'. This operation might require other priviledges.
The inner exception System.ComponentModel.Win32Exception was thrown with the
following error message: Access is denied.
I also get the following error for net start:
The service name is invalid.
What is going on? I was able to do everything perfectly the first time. Why is it not working now?
If you have the services window open, close it and then try doing the reinstall again.
Also, don't forget to uninstall the service before reinstalling it. However, in my experience, I'm pretty sure that once the service is installed just replacing the EXE with the updated service and restarting it is sufficient and I have gotten away without having to reinstall the service. YMMV.

How to debug calls to ASP.NET web api in Visual Studio [duplicate]

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

Windows can't start service

I am developing an app to install & run as a Windows service. It's still buggy and stopped unexpectedly (leaving nothing in the Windows Event log either) and when I tried to start it up again I got the error
Windows could not start the {name of service} service on Local Computer.
Error 1067: The process terminated unexpectedly.
I restarted the computer (Server 2008 R2; a virtual machine, in case that makes a difference), no help. Uninstalled and reinstalled my service, and still get that error!
Something on the machine needs cleared out / refreshed so that it will attempt to start the service again. I don't want to rebuild the whole virtual machine but I'm out of ideas.
UPDATE
I forgot to mention that this Windows service -- exact same code & install -- is running on 3 other machines without the above error. Putting in that debugger in OnStart() still sounds like the way to go though.
If you have access to the code, you can add a method Debugger.Break at the first line of the OnStart method.
Once you "break" into the application investigate where the exception is thrown.
You can attach the debugger to a running service. Details at Debug Windows Service Applications.
It's fortunate that you can replicate the problem easily. You can install the .NET Studio with code to debug your problem.
Another technique is to make the Service into a regular app. You know that the suspect code is during Startup. So simply create the app with code in the Startup function, and start debugging from there.
Good luck,
Tommy Kwee

Setting up CruiseControl.NET

I'm trying to set up CruiseControl.NET (1.6)
The installation completes successfully, however i cannot seem to start the actual service.
When running the CCNET.exe i get a console window that the last thing it writes is: Initialising Security.
Running the service from service control manager also does not work..
Trying to access localhost/ccnet returns no response.
What am i missing here? I have installed the product in the past with success, not sure what is wrong this time.
#lysergic-acid - Even if the main config is done (server/ccnet.config) and you are running it from a command prompt, you won't see the web dashboard yet.
If you are installing on IIS7, the setup process for the web dashboard requires steps that aren't in the CC.Net webdashboard setup docs in sourceforge.
What got me working was this CC.Net web dashboard installer page, which is from the Confluence site, rather than the source forge site: http://confluence.public.thoughtworks.org/display/CCNET/Installing+the+Web+Dashboard
In the comments area, there are specifics about IIS7 (I'm assuming that's part of the problem).
I am still having trouble with the service, so I can't help you there, but you can definitely run the web dashboard without the service as long as the cmd prompt version is running.
The setup of the virtual directory for the web front-end might of not completed successfully. Try using the IIS Service Manager to create an application around the Service folder. I think there's an issue with the install if you forget to unblock the download, but I haven't fiddled with it enough to be sure.
Keep in mind that the web front-end and ccnet service are two totally isolated pieces. You should be able to see the web front-end even if the ccnet service doesn't run.
I had trouble one time when installing it and IIS was set to disabled (and thus was not running), I had to uninstall CruiseControl.NET, start IIS and then reinstall CC.Net.
Do you have a firewall that blocks ports? The default port is 21234.
You need both the web part and the service part installed to be able to run CC.Net.

The service process could not connect to the service controller

Hi I am trying to write just a quick demo service. I am following the tutorial from MSDN here:
http://msdn.microsoft.com/en-us/library/zt39148a.aspx
So this tutorial basically sets up an basic service that writes to the event log. It also configures the installation and adds a setup project. So I have tried the installation on a couple of computers, one running Server 2008 R2 and one running Windows 7.
Basically what happens is the setup runs fine, but the service does not show up in the service list. I also checked the event log and receive an error with a description of:
"The service process could not connect to the service controller"
However there is no other information about the error. Does anyone have any idea how to get the service to show up in the service list and to run? Thanks.
One other item I could mention is that the custom log for the service is created however there are no entries.
The message "Service cannot be started. The service process could not connect to the service controller" is logged in the event log everytime you attempt to run a windows service from Visual Studio. Unlike most projects you create in Visual Studio, Windows Service projects cannot be run directly from the development environment by pressing F5. See the following msdn link http://msdn.microsoft.com/en-us/library/sd8zc8ha.aspx
Problem solved. I didn't follow the last part of the tutorial for adding a custom action :) I thought at first it was optional however it appears that is the final part of installing the service. Works perfect now.
You need to add an Installer to your service.
Go to the designer view of your service. click on the "Add Installer" link. This adds objects that are mandatory for the service installation.
Last thing is to make sure you run your installutil.exe with Administrator privileges.
Just uncheck "Enable the Visual Studio hosting process" works for me!

Categories

Resources