c# - 安装在 Windows Server 中时,OWIN SelfHosted 在 Windows 服务项目中出现异常
问题描述
我有一个在 Windows 10 中运行良好的 Winodws 服务解决方案,但它不能在 Windows Server 2012R2 或 Windows Server 2018 中启动
如果我在 Windows 事件中寻找,我会得到这个 FileNotFoundExceptionError:
应用程序:ServicioWindowsPrueba.exe 框架版本:v4.0.30319 描述:el proceso terminó debido a una excepción no controlada。异常信息:System.IO.FileNotFoundException en Microsoft.Owin.Hosting.Services.ServicesFactory.DoCallback(System.Action 2<System.Type,System.Type>) en Microsoft.Owin.Hosting.Services.ServicesFactory.DoCallback(System.Collections.Generic.IDictionary
2<System.String,System.String>, System.Action2<System.Type,System.Type>) en Microsoft.Owin.Hosting.Services.ServicesFactory.Create(System.Collections.Generic.IDictionary
2<System.String,System.String>, System.Action`1<Microsoft.Owin.Hosting.Services.ServiceProvider>) zh Microsoft.Owin.Hosting.WebApp.BuildServices(Microsoft.Owin.Hosting.StartOptions) zh Microsoft。 Owin.Hosting.WebApp.Start(Microsoft.Owin.Hosting.StartOptions) en Microsoft.Owin.Hosting.WebApp.Start[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089] en RestOwin。 RestOwinServidor.Start() zh System.Threading.ThreadHelper.ThreadStart_Context(System.Object) zh System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) zh System.Threading。 ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) en System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback, System.Object) 和 System.Threading.ThreadHelper.ThreadStart()
这是我的启动课:
using Owin;
using System.Web.Http;
namespace RestOwin
{
public class Startup
{
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}"
//routeTemplate: "{controller}/{id}",
//defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
}
}
}
这是我的服务器类:
using System;
using Microsoft.Owin.Hosting;
using System.Net.Http;
namespace RestOwin
{
public class RestOwinServidor
{
//Puerto de escucha
public int port { get; set; }
public void Start()
{
//try
//{
string baseAddress = "http://127.0.0.1:" + port + "/";
// Start OWIN host
WebApp.Start<Startup>(url: baseAddress);
}
}
}
解决方案
解决了。这是我的错,我只是将 .dll 和 .exe 文件复制到 Windows Server,剩下的文件也很重要
推荐阅读
- c++ - Poco 从 SplitterChannel 获取 Logger Channel
- typescript - 这里的地图:Angular 的自动建议位置
- ruby-on-rails - 在 Rails 中,如何更改资源路由 url 但保持相同的 url 辅助方法?
- javascript - 有没有办法在网络上创建一个二维码阅读器,当你在移动浏览器上打开它时也兼容
- jenkins - Jenkins 声明式管道:如何将文件(在不同节点中退出)数据获取到数组中
- go - Golang 中用于匹配传递的变量和类型的通用函数
- reactjs - React MapBox GL地理编码器在地图外输入是可能的吗?
- c# - 它是什么:int l 当 l>0 && l<5
- json - 解析Json数组以获取值
- ftp - NiFi putFTP效率不高