AddressAccessDeniedException“;您的进程没有对此命名空间的访问权限;当单元测试WCF服务时

AddressAccessDeniedException“;您的进程没有对此命名空间的访问权限;当单元测试WCF服务时,wcf,Wcf,我正在测试我的WCF服务,但我需要伪造行为,因为我的服务是使用自定义工厂引导的。 这是我为测试编写的代码: var channelFactory = new ChannelFactory<IDomainWriteService>( new CustomBinding( new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement()), new Endpoin

我正在测试我的WCF服务,但我需要伪造行为,因为我的服务是使用自定义工厂引导的。 这是我为测试编写的代码:

var channelFactory = new ChannelFactory<IDomainWriteService>(
   new CustomBinding(
      new BinaryMessageEncodingBindingElement(), 
      new HttpTransportBindingElement()),
   new EndpointAddress(new Uri("local")));
var service = channelFactory.CreateChannel();
我已通过以下方式在MsTest项目中配置了一个假端点:

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

我在Windows 8上

您需要使用
netsh add urlacl
来允许监听进程能够在端口80上接收(或与其他监听程序共享端口80)

其中,
YOURUSER
是运行侦听器的进程的凭据,例如,
DOMAIN\User


另请参见:

是的,它对我有效。请注意,注册时尾随斜杠很重要,否则您将得到一个错误87:netsh http add urlacl url=http://+:12345/user=domain\username请注意12345末尾的/!
<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>
    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.
netsh http add urlacl url=http://+:80/service user=YOURUSER