一、问题描述
参考了这篇博客的DEMO:
控制台输出遇到的异常问题:
Web服务开启失败:HTTP 无法注册 URL http://+:7788/。进程不具有此命名空间的访问权限(有关详细信息,请参见 http://go.microsoft.com/fwlink/?LinkId=70353)。
在 System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
在 System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
在 System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
在 System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.HttpChannelListener`1.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open()
在 RestFulService.Program.Main(String[] args) 位置 C:\Users\lanmage2\Desktop\Restful-Service-And-Restful-Client-master\RestFulService\Program.cs:行号 21
二、原因
https://yq.aliyun.com/articles/315251此问题是因为在Win7及以后系统中运行注册URL的程序需要具有管理员特权。
三、解决办法
以管理员身份启动VS2015,然后运行程序即可。