views:

871

answers:

5

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?

+2  A: 

Make sure you are starting VS as administrator..

markt
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 at KBS
+5  A: 

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
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 at KBS
AFAIK you'll only need to do it once (per namespace/user pair you want to reserve)
mostlytech
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
A: 

I was having a similar problem here:

http://stackoverflow.com/questions/530286/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

Andy White
A: 

Advise of mostlytech works greatly for me!

+1  A: 

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
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