Windows services Owin自托管服务不释放端口

Windows services Owin自托管服务不释放端口,windows-services,owin,Windows Services,Owin,我在一个控制台应用程序中安装了一个Owin自托管Web.Api,它是作为windows服务安装的 假设服务的url为。当我重新启动windows服务时,该服务不会重新启动,因为我遇到以下异常 应用程序:xxx.exe 框架版本:v4.0.30319 描述:由于未处理的异常,进程已终止。 异常信息:System.Net.HttpListenerException 在System.Net.HttpListener.AddAllPrefixes()中 在System.Net.HttpListener.

我在一个控制台应用程序中安装了一个Owin自托管Web.Api,它是作为windows服务安装的

假设服务的url为。当我重新启动windows服务时,该服务不会重新启动,因为我遇到以下异常

应用程序:xxx.exe 框架版本:v4.0.30319 描述:由于未处理的异常,进程已终止。 异常信息:System.Net.HttpListenerException 在System.Net.HttpListener.AddAllPrefixes()中 在System.Net.HttpListener.Start()中 在Microsoft.Owin.Host.HttpListener.owinhttpplistener.Start(System.Net.HttpListener,System.Func
2,System.Collections.Generic.IList
1,System.Collections.Generic.IDictionary
2,System.Func
2,Boolean>>) 位于Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(System.Func
2,System.Collections.Generic.IDictionary`2)

这与您尝试在已在使用的端口上运行Owin应用程序时遇到的异常情况相同

因此,我在服务运行时使用netstat,实际上端口已被占用,但当我停止windows服务时,应用程序仍在使用该端口。最终,过了一段时间,端口不再显示在netstat中,然后应用程序将毫无问题地启动

有没有办法在服务重新启动时自动执行此操作,而不必一直尝试直到成功


免责声明:不是网络相关事物的专家……

新手错误。我没有处理Owin网络应用程序,一旦我这样做了,问题就迎刃而解了。