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

编程入门 行业动态 更新时间:2024-10-22 17:25:30
本文介绍了AddressAccessDeniedException "您的进程没有访问此命名空间的权限";单元测试 WCF 服务时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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();

我有一个测试初始化​​,它正在创建一个新的 ServiceHost:

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

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

我以下列方式在我的 MsTest 项目中配置了一个假端点:

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/fwlink/?LinkId=70353 for details). ---> 
System.Net.HttpListenerException: Access is denied.

我使用的是 Windows 8

I am on Windows 8

推荐答案

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

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

其中 YOURUSER 是运行侦听器的进程的凭据,例如域\用户.

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

另见:WCF ServiceHost 访问权限

这篇关于AddressAccessDeniedException "您的进程没有访问此命名空间的权限";单元测试 WCF 服务时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 19:50:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:您的   进程   单元测试   权限   空间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!