0
我运行Windows 7和Visual C#速成2010年的ServiceHost绑定到多个主机名/基址
我在我的ACL以下规则:
Reserved URL : http://www.example.com:8020/gamerecords/
User: Myricae\Dario
Listen: Yes
Delegate: No
SDDL: D:(A;;GX;;;S-1-5-21-3389095862-38437692-3014067205-1001)
不在于它真的很重要,但我也有一个相应的条目在我主机文件:
127.0.0.1 www.example.com
我想自托管的WCF服务控制台应用程序中:
var baseAddress = new Uri("http://www.example.com:8020/gamerecords/");
using (ServiceHost host = new ServiceHost(typeof(Acme.Gaming.GameRecordsImpl), baseAddress))
{
...
}
我得到以下异常:
Unhandled Exception: System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8020/gamerecords/. 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
的原因是,的ServiceHost试图绑定到任何主机名(+),但该规则只授权的主机名当前用户www.example.com。如果我将规则更改为:
Reserved URL : http://+:8020/gamerecords/
User: Myricae\Dario
Listen: Yes
Delegate: No
SDDL: D:(A;;GX;;;S-1-5-21-3389095862-38437692-3014067205-1001)
一切正常。但我不认为ServiceHost应该真的尝试绑定到任何主机名;相反,它应该只发布www.example.com的服务。 为什么WCF试图绑定到多个主机名?。
我发现a page其中描述了类似的问题。
谢谢你的回答。我用这些规则填充ACL的原因是因为我想避免以管理员权限运行应用程序。如果我以管理员身份运行该应用程序,它可以工作,但我不明白为什么它会尝试绑定到任何主机名而不是* www.example.com *。 – damix911
我认为不仅WCF,一般情况下,如果您需要打开一台计算机上的端口Windows需要您作为管理员运行。检查出来 - http://msdn.microsoft.com/en-us/library/ms730935(v=vs.110).aspx –