WCF Service Host Configuration - Please try changing the HTTP port to 8732

StackOverflow https://stackoverflow.com/questions/23521033

  •  17-07-2023
  •  | 
  •  

Question

I had a complex WCF service based solution working on my PC but due to a problem installing Windows 8.1 I had to 'Refresh' my PC. Now that I've reinstalled Visual Studio 2012 my project no longer functions correctly.

When I debug a unit test the wcfservicehost displays an error:

Please try changing the HTTP port to 8733 or running as Administrator.
System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8732/Design_Time_Addresses/MyWCFService/Name/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ---> System.Net.HttpListenerException: Access is denied

Apparently the usual solution to this is to run Visual Studio as administrator (possibly because it then overwrites something somewhere) however I'm unable to do this as I'm required to reference DLLs on a network drive and network drives cannot be accessed when you run as administrator.

I'm assuming that somewhere there is a configuration file or registry entry that determines which port Visual Studio or the WCF Service Host uses when running and that there is a leftover entry in there from my previous Windows installation.

To change the port to 8733 would require editing every service, re-referencing them and then rebuilding the solution and hoping that it works.

Is there a way to set or force the port that WCF Service Host uses?

Was it helpful?

Solution

After a bit of digging around and research I found out that recent versions of Windows enforce security settings that prevent you from listening to any ports. I’m assuming that when Visual Studio is installed it reserves a port for it’s own use so that you can host and thus debug web services. This was the localhost:8732 port on my development machine but with reinstalling Visual studio it is now localhost:8733, unfortunately all my app.config files in the solution point to port 8732.

Run an elevated command prompt and execute netsh http show urlacl. This displays the list of reserved ports amongst which I found this:

Reserved URL            : http://+:8733/Design_Time_Addresses/
User: NT AUTHORITY\INTERACTIVE

Which, I’m assuming, is the entry added when Visual Studio was installed.

Executing the following command reserves the 8732 url/port:

netsh http add urlacl url=http://+:8732/ user=WORK\Clara

Restart Visual Studio and all of a sudden my solution works again.

OTHER TIPS

Step 1: Run cmd.exe as local administrator

Step 2: Run the command below to enable http on port 1234

netsh http add urlacl url=http://+:1234/ user=Everyone listen=yes

Hint: The name of the user "Everyone" can differ and depend on your OS’s installation language. In German for example the user is not called "Everyone", but "Jeder".

Another option is to bypass port-specific access control lists and enable the wcfservicehost to run as Administrator.

You can do this by finding the wcfsvchost.exe in your file system (e.g. C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\wcfsvchost.exe), right-clicking the file and selecting 'Compatibility' tab.

In there, you can select 'Run this program as an administrator', if you are an administrator (and you should be if you are rocking stackoverflow ;-)).

Restart Visual Studio, and you should be good to go.

Simply restarting it as administrator can solve it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top