4

I put together a small WCF service in VS2008 and when I try to run the host using an HTTP protocol, it bombs because it doesn't have the proper rights to do so. On my "Host.Open()" line I get this exception: "HTTP could not register URL http://+:9001/. Your process does not have access rights to this namespace." I did not seem to have this problem using TCP. My o/s is Vista Home Premium.

This was happening when I would try to Debug it inside VS2008. After a lot of research, I determined I could get the host to run by building, going to the "bin" folder, and right-clicking on my executable, selecting "Run as Administrator". The same thing happened when I tried to use the WcfSvcHost.exe. I had to open the VS2008 Command Prompt window from my menu using "Run as Admin" before I could successfully get WcfSvcHost to run my service.

Is there a way to do this right instead of using this workaround? Am I going to have similar problems when I try to deploy this next week on a Windows 2003 Server?

BIBD
  • 15,107
  • 25
  • 85
  • 137
Mike K
  • 1,313
  • 2
  • 18
  • 28

4 Answers4

7

This link might help you: http://msdn.microsoft.com/en-us/library/ms733768.aspx

Short version: pre-register the url/namespace from a privileged console

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

mostlytech
  • 814
  • 9
  • 13
  • I tried this yesterday and couldn't get it to work. Your point that it should be a "privileged console" clued me in that I should do Command Prompt "as Admin". I tried this just now and it worked. I guess I'll have to do this after every reboot? – Mike K Feb 28 '09 at 21:16
  • AFAIK you'll only need to do it once (per namespace/user pair you want to reserve) – mostlytech Feb 28 '09 at 21:58
  • You might have to give the account that is running the service administrator rights. That way you wouldn't have to re-do it every reboot – Andy White Mar 01 '09 at 01:30
2

Make sure you are starting VS as administrator..

markt
  • 5,126
  • 31
  • 25
  • Good point. My account is an Admin account but I often forget that nothing I do is granted Admin unless I request that explicitly. Frustrating... – Mike K Feb 28 '09 at 21:13
1

Locally, you can change your base address to something like this:

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8731/Design_Time_Addresses/MyService/" />
      </baseAddresses>
    </host>

The main part being the addition of "Design _ Time _ Addresses". If you create a WCF Service Library project, it sets up the App.config for the project like this by default. Everything works fine this way, but if you remove "Design _ Time _ Addresses" and try to run it with "http://localhost:8731/MyService/", you will get the error that you are running into.

Josh Close
  • 22,935
  • 13
  • 92
  • 140
  • This works perfect for when you are trying to set up a unit test where you want to bind to http, and exercise the service using an http channel. – Kris Feb 06 '10 at 00:59
0

I was having a similar problem here:

WCF ServiceHost basicHttpBinding 503 error

The netsh command works for Vista, but for Windows 2003 server, there is an HttpCfg.exe utility that allows you to register a URL/namespace for an account. Not sure if the netsh is available in 2003.

I never actually got it to work on Vista, I'm still getting 503 errors when I try to access the services. If you run into the same problem/figure it out, I'd appreciate it if you post again! Thanks

Community
  • 1
  • 1
Andy White
  • 86,444
  • 48
  • 176
  • 211