【发布时间】:2017-05-18 11:25:17
【问题描述】:
我有一个非常简单的 WCF 服务 - 这是服务合同:
[ServiceContract]
public interface IHelloService
{
[OperationContract]
string SayGreeting(string name);
[OperationContract]
string SayRudeGreeting(string name);
}
这是实现:
public class HelloService : IHelloService
{
public string SayGreeting(string name)
{
return "Well, hello there, " + name;
}
public string SayRudeGreeting(string name)
{
return string.Format("What do you want, {0} ?", name);
}
}
这不是有趣的部分 :-) 我想做的是 self-host 在 Windows 命令行应用程序中提供这个简单的服务。我正在使用以下代码行:
Uri baseAddress = new Uri("http://localhost:9099");
using (ServiceHost host = new ServiceHost(typeof(HelloService), baseAddress))
{
host.Open();
Console.WriteLine("HelloService is up and running ....");
Console.ReadKey();
Console.WriteLine("HelloService - closing down...");
}
我有一个非常简单直接的app.config 用于该主机:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="DevDebug">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfService1.HelloService"
behaviorConfiguration="DevDebug">
<endpoint
address="HelloService"
binding="wsHttpBinding"
contract="WcfService1.IHelloService" />
<endpoint
address="HelloService/mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
没有什么特别的 - 只是一个普通的 wsHttpBinding 端点 http://localhost:9099/HelloService 和一个 MEX 端点。
当我构建这个主机和 WCF 服务,并在我以“管理员身份”启动的 Visual Studio 2015 中运行主机时,我收到了这条奇怪的消息:
System.ServiceModel.AddressAccessDeniedException 未处理
HResult=-2146233087
消息=HTTP 无法注册 URL http://+:9099/。您的进程没有对此命名空间的访问权限(有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=70353)。
?!?!?!?!?我是我的盒子上的ADMINISTRATOR - 为什么不允许我注册此 URL!?!?
我怀疑这是 Windows 10 (Professional - v1607) 的一个新“功能” - 因为我非常确定,这个设置过去只是工作在我以前的 Windows 7 机器上很好。
好的 - 所以我从命令行启动我的 WCF 主机,明确地以管理员身份 - 现在主机出现并且一切看起来都很好,我可以从 WCF 测试客户端连接到它,并且我的代码似乎运行良好。
但是,如果我现在尝试使用 SoapUI 或仅使用 IE 11 连接到它,我会不断收到另一批似乎表明此 URL 的错误消息(“无效页面”等)无法访问.....
为什么!?!
我需要在 Windows 10 专业版中做什么才能使 WCF 自托管再次工作!?
谢谢!
【问题讨论】:
标签: wcf windows-10 self-hosting