【发布时间】:2016-02-12 11:05:51
【问题描述】:
我想在我的 WPF 应用程序中实现一个简单的自托管 REST API,它侦听 localhost 上的特定端口。如果 WPF 应用程序正在运行,该 API 将被网站使用,以便与 WPF 应用程序进行通信。
没过多久我就遇到了 System.ServiceModel.AddressAccessDeniedException 错误。必须保留 URL,并且只有在进程以提升的权限运行时才能做到这一点。问题在于,该应用程序在数千家公司使用不同的 IT 策略,这使得该应用程序几乎不可能在每次启动时都需要管理权限。
这是我的测试代码:
_task = Task.Factory.StartNew(() =>
{
var uri = new Uri("http://localhost:5000/test");
var type = typeof (TestService);
WebServiceHost host = new WebServiceHost(type, uri);
WebHttpBinding binding = new WebHttpBinding();
binding.CrossDomainScriptAccessEnabled = true;
host.AddServiceEndpoint(type, binding, uri);
host.Open();
});
有没有办法解决这个问题?我可以使用任何 3rd 方包吗?或者我可以在安装应用程序期间保留 URL,因为安装需要提升的权限?或者这是一个死胡同?
【问题讨论】:
标签: c# .net windows wcf self-hosting