I have created my first self-hosted WCF service. I hosted it in a C# console app but it throws an error:
System.ServiceModel.AddressAccessDeniedException
Root path URL (http://+:8080/) permissions are needed in your case:
netsh http add urlacl url=http://+:8080/ user=%USERDOMAIN%\%USERNAME%
show all URL reservations:
netsh http show urlacl | FIND "URL"
I ran into the same problem on a different project.
The problem is that binding to a tcp port requires administrative privileges. There's a couple ways to deal with this.
Keep an administrative command prompt open. Then you can just run the console app directly.
(As you suggested) run VS as admin. This is absolutely necessary only when debugging your app.
Create an application manifiest file, specifying requestedExecutionLevel level="requireAdministrator". See How do I force my .NET application to run as administrator? for more details.
If you ran into this error while starting the service on Windows Service, you can check the account on your process installer.
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
private ServiceProcessInstaller process;
private ServiceInstaller service;
public ProjectInstaller()
{
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service = new ServiceInstaller();
service.ServiceName = "WCFWindowsServiceSample";
Installers.Add(process);
Installers.Add(service);
}
}
Start the cmd as Administrator and enter:
netsh http add urlacl url=http://+:8080/MyUri user=DOMAIN\user
this worked for me.
Just Save your Work & Run your IDE i.e VS in Admin mode.