System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http::8080

后端 未结 5 1388
终归单人心
终归单人心 2021-02-02 08:45

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

相关标签:
5条回答
  • 2021-02-02 08:58

    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"
    
    0 讨论(0)
  • 2021-02-02 09:06

    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.

    1. Keep an administrative command prompt open. Then you can just run the console app directly.

    2. (As you suggested) run VS as admin. This is absolutely necessary only when debugging your app.

    3. Create an application manifiest file, specifying requestedExecutionLevel level="requireAdministrator". See How do I force my .NET application to run as administrator? for more details.

    0 讨论(0)
  • 2021-02-02 09:08

    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);
        }
    }
    
    0 讨论(0)
  • 2021-02-02 09:19

    Start the cmd as Administrator and enter:

    netsh http add urlacl url=http://+:8080/MyUri user=DOMAIN\user
    

    this worked for me.

    0 讨论(0)
  • 2021-02-02 09:23

    Just Save your Work & Run your IDE i.e VS in Admin mode.

    0 讨论(0)
提交回复
热议问题