Ever came across any of these errors while hosting WCF on windows service?
1. The xxx service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
2. Service cannot be started. System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL http://+:8011/PersistanceManager/ because TCP port 8011 is being used by another application. ---> System.Net.HttpListenerException: The process cannot access the file because it is being used by another process
Solution for problem 1: To find the root cause of the error, look into the event viewer. The most probable cause would the that the referenced assemblies or the app.config would not be present in the same directory as the executable. Also when you copy the app.config, make sure to rename it as applicationname.exe.config.
Solution for problem 2: Check if you have provided a port number for the mex address. Mex doesnt require a port number, so you can saferly remove it and the problem would be solved. If the problem still persists, check if any other application is using the same port number. You can make use of netsh command to accomplish this (search for how to use this command). If you are not running under administrative privilages, you can even allow everyone to make use of the port using the netsh command.
This should solve your problem in almost all cases. In case the problem still persists, do feel free to leave a comment and I will revert back. Happy coding! 🙂