c# - 如何让我的自托管 WCF 服务不尝试保留 localhost 以外的 url?
问题描述
我想在 .NET 3.5 桌面应用程序中嵌入一个 REST API。在该框架版本上,只有一个选项:自托管 WCF。
但我似乎无法让它只在 localhost 上监听。
启动时,该应用程序尝试为 进行 url 预订,但 由于我没有以管理员权限运行它http://+:8000
而失败。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();
}
}
}
我能做些什么 ?
解决方案
下面的命令可以解决问题吗?
- 适用于 Windows Vista、Windows7
netsh http 添加 urlacl url= http://+:8000/MyUri user=DOMAIN\user
- 对于 Windows XP、Server2003。
httpcfg 设置 urlacl /u { http://URL:Port/ | https://URL:Port/ } /a ACL
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-http-and-https
https://docs.microsoft.com/en-us/windows/desktop/http /add-urlacl
如果问题仍然存在,请随时告诉我。
推荐阅读
- python - 使用 python-telegram-bot 发送视频时出错,包括通过 python 的缩略图
- python - 找到具有 O(n+k) 时间复杂度的三元组
- google-apps-script - 如何使 Google Apps 脚本作为访问它的用户执行而不会出现 CORS 错误
- r - mraplot 中的函数 text.default() 出错
- python - 对变量使用特殊字符
- python - django不在模板中显示表单
- python - 在窗口上导入 matplotlib 时出现运行时错误
- python - 如何制作正确的静音命令,在取消静音时静音并在静音时取消静音
- python - max_length 不修复问答模型
- javascript - 是否可以与 node sqlite3 命令一起使用 import txt fil 并改进批量插入?