[英]How can I make my self-hosted WCF service NOT try to reserve urls other than localhost?
我想在.NET 3.5桌面应用程序中嵌入REST API。 在该框架版本上,只有一个选择:自托管WCF。
但是我似乎无法使其仅在本地主机上侦听。
启动时,应用程序尝试为http://+:8000
进行URL保留,但由于System.ServiceModel.AddressAccessDeniedException
而失败,因为我没有以管理员权限运行它。
我希望它仅保留http://localhost:8000
,从而避免需要管理员权限。
使用HostNameComparisonMode.Exact
似乎没有任何改变。
这是我尝试过的:
using Myservice;
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
namespace consolehost1
{
class Program
{
static void Main(string[] args)
{
//Use exact hostname comparison mode
WebHttpBinding binding = new WebHttpBinding();
binding.HostNameComparisonMode = HostNameComparisonMode.Exact;
WebServiceHost host = new WebServiceHost(typeof(Service1), new Uri("http://localhost:8000/"));
ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IService1), binding, "some-endpoint");
//The host still tries to get a reservation for http://+:8000 and not just http://localhost:8000
host.Open();
}
}
}
我能做什么 ?
以下命令可以解决该问题吗?
httpcfg set urlacl / u { http:// URL:Port / | https:// URL:Port / } / a ACL
https://docs.microsoft.com/zh-cn/dotnet/framework/wcf/feature-details/configuring-http-and-https
https://docs.microsoft.com/zh-CN/windows/desktop/http/add-urlacl
随时让我知道问题是否仍然存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.