HTTP could not register URL http://+:8000/HelloWCF/. Your process does not have access rights to this namespace

I'm a beginner in WCF, but trying to improve my experience. And on the first step I faced the problem. I created the simplest WCF service. The listing of code: (all the code in one file)

using System;
using System.ServiceModel;

namespace EssentialWCF
{
    [ServiceContract]
    public interface IStockService
    {
        [OperationContract]
        double GetPrice(string ticker);
    }

    public class StockService : IStockService
    {
        public double GetPrice(string ticker)
        {
            return 94.85;
        }
    }

    class Service
    {
        static void Main(string[] args)
        {
            ServiceHost serviceHost = new ServiceHost(typeof(StockService),
                                                        new Uri("http://localhost:8000/HelloWCF"));

            serviceHost.AddServiceEndpoint(typeof(IStockService), new BasicHttpBinding());
            serviceHost.Open();

            Console.WriteLine("To continue press ENTER");

            serviceHost.Close();
        }
    }
}

That would be the service that give me a number via console. But debug give me the exception: (instead of number :) )

HTTP could not register URL http://+:8000/HelloWCF/. Your process does not have access rights to this namespace.

Have you ever faced the same situation? I will be glad to see every advice.


Solution 1:

Unfortunately the link in the exception text, http://go.microsoft.com/fwlink/?LinkId=70353, is broken. However, it used to lead to http://msdn.microsoft.com/en-us/library/ms733768.aspx which explains how to set the permissions.

It basically informs you to use the following command:

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

You can get more help on the details using the help of netsh

For example: netsh http add ?

Gives help on the http add command.

Solution 2:

I closed Visual studio IDE and reopened it by right clicking on the Visual Studio icon and saying "Run as Administrator", Then when I ran the host , It worked!!!

Solution 3:

Right Click on Visual Studio > Run as Administrator > Open your project and run the service. This is a privilege related issue.

Solution 4:

You need some Administrator privilege to your account if your machine in local area network then you apply some administrator privilege to your User else you should start ide as Administrator...