Service cannot be started. Could not register URL

Harry picture Harry · Dec 16, 2012 · Viewed 14.5k times · Source

I want to host wcf in window service. I've done several times before without any problem. This time After I installed the service and click on start I get the following error in EventViewer.

Service cannot be started. System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:.../.../. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).

When I host the same service, same address on ConsoleApplication - all right.

I saw the questions here and here, but none of the solutions helped me.

Does anyone have an idea?

Answer

CodeCaster picture CodeCaster · Dec 16, 2012

As for your answer, that's a bit of shotgun debugging. You now have a network service with administrator privileges:

LocalSystem Account (Windows):

The LocalSystem account [...] has extensive privileges on the local computer, and acts as the computer on the network. Its token includes the NT AUTHORITY\SYSTEM and BUILTIN\Administrators SIDs; these accounts have access to most system objects.

Most services do not need such a high privilege level. If your service does not need these privileges, and it is not an interactive service, consider using the LocalService account or the NetworkService account. For more information, see Service Security and Access Rights.

So you'd better run this service as NetworkService, and give it the proper permissions to use the port you're trying to use as explained in Configuring HTTP and HTTPS:

netsh http add urlacl url=http://+:80/MyUri user="NT AUTHORITY\NETWORK SERVICE"