【发布时间】:2018-08-23 15:33:31
【问题描述】:
我有一个现有的 Windows 服务。目标是拥有一个 REST 接口来与此服务进行通信。我认为只制作一个 ASP.NET Core Web 应用程序(参见屏幕截图)并在我现有的服务中启动整个事情可能是一个好主意。然后他们可以共享同一个 IOC 容器等等。
然后我用sc create s1 binPath = "pathgoeshere"注册了服务
当我启动服务(附加到进程以进行调试)时,输出窗口中出现错误:
Exception thrown: 'System.DllNotFoundException' in Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.dll
The thread 0x5250 has exited with code 0 (0x0).
Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
'WindowsService1.exe' (CLR v4.0.30319: WindowsService1.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceProcess.resources\v4.0_4.0.0.0_de_b03f5f7f11d50a3a\System.ServiceProcess.resources.dll'. Module was built without symbols.
Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
The thread 0x4fa0 has exited with code 0 (0x0).
Microsoft.AspNetCore.Server.Kestrel: Warning: Unable to bind to http://localhost:5000 on the IPv4 loopback interface: 'Die DLL "libuv": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.'.
Exception thrown: 'System.DllNotFoundException' in Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.dll
The thread 0x58c4 has exited with code 0 (0x0).
Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
Microsoft.AspNetCore.Server.Kestrel: Warning: Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Die DLL "libuv": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.'.
Exception thrown: 'System.IO.IOException' in Microsoft.AspNetCore.Server.Kestrel.Core.dll
Exception thrown: 'System.IO.IOException' in mscorlib.dll
Exception thrown: 'System.IO.IOException' in mscorlib.dll
Exception thrown: 'System.IO.IOException' in mscorlib.dll
Microsoft.AspNetCore.Server.Kestrel: Critical: Unable to start Kestrel.
我把整个例子放在了 GitHub 上:
https://github.com/SuperSludge/aspnetcoreService
有人做过这样的事吗?我完全走错了路吗?将整个 Windows 服务重写为 ASP.NET Core App 是否更容易?
【问题讨论】:
-
看来您的方法应该可行。您是否查看过 Windows 服务文档中的 Host ASP.NET Core? docs.microsoft.com/en-us/aspnet/core/host-and-deploy/…
-
@ShaunLuttin 是的,我看过这个。问题是我有2个项目。一个现有的 Windows 服务和一个新的 Rest API 项目。正如我所提到的,如果我能够获得 Asp.NET 核心 API 的所有好处,但将其托管在现有项目中,那就太好了。否则我将不得不安装、注册、维护 2 个 Windows 服务。或者(正如我提到的)在 ASP.NET 核心应用程序中重写整个服务。
标签: c# asp.net-core windows-services