AddressAccessDeniedException thrown when starting a service with ServiceHost on Localhost

I’ve been working my way through Apress’ “Introducing dot Net 4.0 with Visual Studio 2010” to get a handle on what’s new in the latest version of my environment. I skipped this step when moving from 2.0 to 3.5 which led to me missing quite a few great tips, which I was determined would not happen this time.

Working through Chapter 7, WCF Services, I’ve found something the book author seems to have missed. One of his code samples fails to work for some people, including myself. I tracked down the problem to the fact I was running Vista (strangely, I would assume the problem exists then on Windows 7, the authors operating system, but maybe not).

Basically, the example instructs you, having written a service, to create a console app that registers a ServiceHost object and open it, thus starting your service. This is done like this:

ServiceHost Host = new ServiceHost(typeof(YourServiceType), new Uri(“http://localhost:8888/myservice”); Host.Open();

After this, assuming all goes well, you can browse to localhost:8888/myservice and view the service as published. For me, it didn’t go well. I hit F5 and as the application began to run, it threw an AddressAccessDeniedException claiming that I didn’t have access rights to create an endpoint at that address.

This is confusing of course, until you realise that Vista requires you to elevate your permissions to do various things, one of which is open ports and create address endpoints. F5 in Visual Studio is completely unable to perform this task.

I have found two solutions to this issue.

The first, given that in this particular example we’re using a console app, is to open a command prompt with full administrator access (Run As Administrator), change directory to the bin/debug directory of the program and run it from there. It works fine.

The second is to open Visual Studio itself with full administrator access and then F5 will work as expected. It’s an interesting little bug/feature and worth keeping in mind next time you stumble over an unexpected access denied issue.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s