2
votes

I am testing my WCF services but I need to fake the behavior because my services are bootstrapped using a custom factory. This is the code I wrote for my test:

var channelFactory = new ChannelFactory<IDomainWriteService>(
   new CustomBinding(
      new BinaryMessageEncodingBindingElement(), 
      new HttpTransportBindingElement()),
   new EndpointAddress(new Uri("local")));
var service = channelFactory.CreateChannel();

And I have a test initialize which is creating a new ServiceHost:

internal static void StartService()
{
    Instance = new ServiceHost(typeof (DomainWriteService));
    Instance.Open();
}

I have configured a fake endpoint in my MsTest project in the following way:

<service name="xxx.DomainWriteService">
  <endpoint binding="basicHttpBinding" bindingConfiguration=""
    name="local" bindingName="http" contract="xxx.IDomainWriteService" />
  <host>
    <baseAddresses>
      <add baseAddress="http://xxx/service" />
    </baseAddresses>
  </host>
</service>

But when I run my tests I get this runtime error:

    Class Initialization method xxx.ClassInitialize threw exception. System.ServiceModel.AddressAccessDeniedException: 
System.ServiceModel.AddressAccessDeniedException: 
HTTP could not register URL **http://+:80/service/**. 
Your process does not have access rights to this namespace 
(see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ---> 
System.Net.HttpListenerException: Access is denied.

I am on Windows 8

1
Yes please, it worked for me.Raffaeu

1 Answers

6
votes

You'll need to use netsh add urlacl to allow access for the process listening to be able to receive on port 80, (or share port 80 with other listeners)

netsh http add urlacl url=http://+:80/service user=YOURUSER

Where YOURUSER is the credentials of the process running the listener, e.g. DOMAIN\User.

See also: WCF ServiceHost access rights