我正在测试我的 WCF 服务,但我需要伪造行为,因为我的服务是使用自定义工厂引导的。这是我为测试编写的代码:
var channelFactory = new ChannelFactory<IDomainWriteService>(
new CustomBinding(
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()),
new EndpointAddress(new Uri("local")));
var service = channelFactory.CreateChannel();
我有一个测试初始化,它正在创建一个新的 ServiceHost:
internal static void StartService()
{
Instance = new ServiceHost(typeof (DomainWriteService));
Instance.Open();
}
我通过以下方式在我的 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>
但是当我运行我的测试时,我得到了这个运行时错误:
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.
我在 Windows 8 上