尝试在Windows 10 1703(15063.483)中使用自托管的webapi应用程序时开始出现异常
VS2017:版本15.2(26430.15)发布 VisualStudio.15.Release / 15.2.0 + 26430.15
我尝试在管理员模式下运行VS,结果与非管理员模式相同。 我的应用正在尝试使用http://192.168.12.118:50231 该项目是.NET 4.5 WPF应用程序。
第一次应用失败后,我做了:
netsh http add urlacl url = http://+:50231/ user = AD \ USER
netsh http show url =>显示注册确定
这是我正在使用的代码:
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(new Uri("http://" + MyIP + ":" + MyPort));
config.MaxReceivedMessageSize = Int32.MaxValue - 1000;
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Startup server
server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
当我执行命中OpenAsync时,这是我得到的例外:
.Inner Type: AddressAlreadyInUseException
.Inner Message: HTTP could not register URL http://+:50231/ because TCP port 50231 is being used by another application.
.Inner Stack: at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.CommunicationObject.EndOpen(IAsyncResult result)
at System.Web.Http.SelfHost.HttpSelfHostServer.OpenListenerComplete(IAsyncResult result)
..Inner Type: HttpListenerException
..Inner Message: The process cannot access the file because it is being used by another process
..Inner Stack: at System.Runtime.AsyncResult.End[TAsyncResult] (IAsyncResult result)
at System.ServiceModel.Channels.CommunicationObject.EndOpen(IAsyncResult result)
at System.Web.Http.SelfHost.HttpSelfHostServer.OpenListenerComplete(IAsyncResult result)`
TIA
答案 0 :(得分:2)
“你重启了吗?”这样做了。对我来说没有意义,因为没有列出任何使用该端口的东西......哦,好吧。