WCF – Windows Service Hosting Error Resolutions

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! 🙂

Comments (5)
  1. cron22 says:

    Thank you for this post!  I'm sure it will come in handy to me once I learn WCF, and I will remember this one.  I am curious why it matters that the app.config file is renamed to applicationName.exe.config though?  

  2. By convention, .Net will only read configuration files that has the same name as the executable. Therefore, renaming it will only work if you have your own custom code to read the file.

  3. cron22 says:

    That's funny because I could swear that I have seen some applications in the past in which the config file was just called app.config.  Can that stil happen these days?  

  4. Here we are talking about wcf hosted in windows service. If you are creating a wcf app hosted on IIS, it would be web.config. When you create a wcf application, the config file would be called app.config. When you build the application, visual studio would place the app.config as applicationname.exe.config in the output directory.

  5. cron22 says:

    Oh cool.  I guess then that it's just because I haven't quite gotten to that one yet.  

Comments are closed.

Skip to main content