Starts in:
1 DAY
10 HRS
53 MIN
42 SEC
Starts in:
1 D
10 H
53 M
42 S
Open Closed

Hosting api as Windows Service #1005


User avatar
0
can.ercan created
  • ABP Framework version: v4.2.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes / no
  • Exception message and stack trace:
  • Steps to reproduce the issue:

When i try to host the HttpApi.Host as a Windows Service i can't reach the localhost page and get Http Error 500.

i installed Microsoft.Extensions.Hosting and Microsoft.AspNetCore.Hosting nuget packages Below is my Program.cs code:

public static int Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
#if DEBUG
.MinimumLevel.Debug()
#else
.MinimumLevel.Information()
#endif
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Async(c => c.File("Logs/logs.txt"))
#if DEBUG
.WriteTo.Async(c => c.Console())
#endif
.CreateLogger();

        try
        {
            Log.Information("Starting IPCDataApp.HttpApi.Host.");
            CreateHostBuilder(args).Build().Run();
            return 0;
        }
        catch (Exception ex)
        {
            Log.Fatal(ex, "Host terminated unexpectedly!");
            return 1;
        }
        finally
        {
            Log.CloseAndFlush();
        }
    }


internal static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();

webBuilder.ConfigureKestrel(serverOptions =>
{
serverOptions.Limits.MaxConcurrentConnections = 100;
serverOptions.Limits.MaxConcurrentUpgradedConnections = 100;
serverOptions.Limits.MaxRequestBodySize = 30 \* 1024 \* 1024;
serverOptions.Limits.MinRequestBodyDataRate =
new MinDataRate(bytesPerSecond: 100,
gracePeriod: TimeSpan.FromSeconds(10));
serverOptions.Limits.MinResponseDataRate =
new MinDataRate(bytesPerSecond: 100,
gracePeriod: TimeSpan.FromSeconds(10));
serverOptions.Limits.KeepAliveTimeout =
TimeSpan.FromMinutes(2);
serverOptions.Limits.RequestHeadersTimeout =
TimeSpan.FromMinutes(1);
serverOptions.Listen(IPAddress.Any, 5050);
});
})
.UseAutofac()
.UseSerilog()
.UseWindowsService();
}

After i publish the app and create the windows service Service starts without a problem. But when i try to reach the website http:\localhost:5050 i get htpp error 500. I would be grateful if you can help with the proble,

F.Can Ercan, SW Developer Merlin Yazilim


7 Answer(s)
  • User Avatar
    0
    can.ercan created

    Below is the log file: 2021-03-05 13:32:23.600 +03:00 [INF] Starting IPCDataApp.HttpApi.Host. 2021-03-05 13:32:25.664 +03:00 [INF] User profile is available. Using 'C:\Users\MONSTER\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. 2021-03-05 13:32:25.739 +03:00 [INF] Loaded ABP modules:


    2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.SettingManagement.AbpSettingManagementDomainModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Saas.SaasDomainModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.TextTemplateManagement.TextTemplateManagementDomainModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.LeptonTheme.Management.LeptonThemeManagementDomainModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.LanguageManagement.LanguageManagementDomainModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Commercial.SuiteTemplates.VoloAbpCommercialSuiteTemplatesModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.BlobStoring.AbpBlobStoringModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.BlobStoring.Database.BlobStoringDatabaseDomainModule 2021-03-05 13:32:25.739 +03:00 [INF] - IPCDataApp.IPCDataAppDomainModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.PermissionManagement.AbpPermissionManagementApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Identity.AbpIdentityApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.FeatureManagement.AbpFeatureManagementApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Saas.Host.SaasHostApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AuditLogging.AbpAuditLoggingApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.IdentityServer.AbpIdentityServerApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Account.AbpAccountSharedApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Sms.AbpSmsModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Account.AbpAccountPublicApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Account.AbpAccountAdminApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.LanguageManagement.LanguageManagementApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.LeptonTheme.Management.LeptonThemeManagementApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.TextTemplateManagement.TextTemplateManagementApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - IPCDataApp.IPCDataAppApplicationModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Users.EntityFrameworkCore.AbpUsersEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Identity.EntityFrameworkCore.AbpIdentityEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.IdentityServer.EntityFrameworkCore.AbpIdentityServerEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.PermissionManagement.EntityFrameworkCore.AbpPermissionManagementEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.SettingManagement.EntityFrameworkCore.AbpSettingManagementEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.EntityFrameworkCore.SqlServer.AbpEntityFrameworkCoreSqlServerModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.BackgroundJobs.EntityFrameworkCore.AbpBackgroundJobsEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AuditLogging.EntityFrameworkCore.AbpAuditLoggingEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.FeatureManagement.EntityFrameworkCore.AbpFeatureManagementEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.LanguageManagement.EntityFrameworkCore.LanguageManagementEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Saas.EntityFrameworkCore.SaasEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.TextTemplateManagement.EntityFrameworkCore.TextTemplateManagementEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.BlobStoring.Database.EntityFrameworkCore.BlobStoringDatabaseEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - IPCDataApp.EntityFrameworkCore.IPCDataAppEntityFrameworkCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - IPCDataApp.EntityFrameworkCore.IPCDataAppEntityFrameworkCoreDbMigrationsModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.AbpAspNetCoreMvcUiModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.AbpAspNetCoreMvcUiBootstrapModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.Bundling.AbpAspNetCoreMvcUiBundlingModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.Packages.AbpAspNetCoreMvcUiPackagesModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.Widgets.AbpAspNetCoreMvcUiWidgetsModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.AbpAspNetCoreMvcUiThemeSharedModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.AbpAspNetCoreMvcUiMultiTenancyModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.LeptonTheme.Management.LeptonThemeManagementWebModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.Theme.Commercial.AbpAspNetCoreMvcUiThemeCommercialModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Mvc.UI.Theme.Lepton.AbpAspNetCoreMvcUiLeptonThemeModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Authentication.JwtBearer.AbpAspNetCoreAuthenticationJwtBearerModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Identity.AspNetCore.AbpIdentityAspNetCoreModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Account.Public.Web.AbpAccountPublicWebModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Account.Web.AbpAccountPublicWebIdentityServerModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.Swashbuckle.AbpSwashbuckleModule 2021-03-05 13:32:25.739 +03:00 [INF] - Volo.Abp.AspNetCore.Serilog.AbpAspNetCoreSerilogModule 2021-03-05 13:32:25.739 +03:00 [INF] - IPCDataApp.IPCDataAppHttpApiHostModule 2021-03-05 13:32:26.112 +03:00 [INF] Starting IdentityServer4 version 4.1.1+cebd52f5bc61bdefc262fd20739d4d087c6f961f 2021-03-05 13:32:26.792 +03:00 [INF] Using the default authentication scheme Identity.Application for IdentityServer 2021-03-05 13:32:27.182 +03:00 [INF] Initialized all ABP modules. 2021-03-05 13:32:27.232 +03:00 [INF] Now listening on: http://0.0.0.0:5050 2021-03-05 13:32:27.232 +03:00 [INF] Application started. Press Ctrl+C to shut down. 2021-03-05 13:32:27.232 +03:00 [INF] Hosting environment: Production 2021-03-05 13:32:27.232 +03:00 [INF] Content root path: E:\Development\abp\IPCDataApp\aspnet-core\src\IPCDataApp.HttpApi.Host\bin\Release\net5.0\win-x64 2021-03-05 13:32:48.591 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:5050/swagger/index.html - - 2021-03-05 13:32:49.485 +03:00 [INF] Request finished HTTP/1.1 GET http://localhost:5050/swagger/index.html - - - 200 - text/html;charset=utf-8 896.3092ms 2021-03-05 13:32:49.819 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:5050/swagger/v1/swagger.json - - 2021-03-05 13:32:49.852 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:5050/swagger/favicon-32x32.png - - 2021-03-05 13:32:49.875 +03:00 [INF] Sending file. Request path: '/favicon-32x32.png'. Physical path: 'N/A' 2021-03-05 13:32:49.875 +03:00 [INF] Request finished HTTP/1.1 GET http://localhost:5050/swagger/favicon-32x32.png - - - 200 628 image/png 22.7019ms 2021-03-05 13:32:50.260 +03:00 [INF] Request finished HTTP/1.1 GET http://localhost:5050/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 440.8839ms 2021-03-05 13:33:03.990 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:5050/swagger/index.html - - 2021-03-05 13:33:04.017 +03:00 [INF] Request finished HTTP/1.1 GET http://localhost:5050/swagger/index.html - - - 200 - text/html;charset=utf-8 27.1017ms 2021-03-05 13:33:04.123 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:5050/swagger/v1/swagger.json - - 2021-03-05 13:33:04.131 +03:00 [INF] Request starting HTTP/1.1 GET http://localhost:5050/swagger/favicon-32x32.png - - 2021-03-05 13:33:04.150 +03:00 [INF] Sending file. Request path: '/favicon-32x32.png'. Physical path: 'N/A' 2021-03-05 13:33:04.150 +03:00 [INF] Request finished HTTP/1.1 GET http://localhost:5050/swagger/favicon-32x32.png - - - 200 628 image/png 18.6576ms 2021-03-05 13:33:04.308 +03:00 [INF] Request finished HTTP/1.1 GET http://localhost:5050/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 184.8791ms 2021-03-05 13:33:09.840 +03:00 [INF] Application is shutting down...

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    This seems related with running Kestrel in windows service. There seems no error related with abp. Can you successfuly run an empty .net5 application, hit kestrel midware and share the results?

  • User Avatar
    0
    can.ercan created

    we succesfully ran an empty asp.net core 5 app in windows service with kestrel.

    With the same steps we get http error 500 when used with abp suite project.

  • User Avatar
    0
    can.ercan created

    We created an Abp suite App and tried the same steps without any changes to project, doesn't work

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Hello, sorry for late response,

    I created a tiered application since you want to use HttpApi.Host it seems.

    Same Program.cs configuration after adding Microsoft.Extensions.Hosting.WindowsServices package;

    internal static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>        {
                webBuilder.UseStartup<Startup>();
    
                webBuilder.ConfigureKestrel(serverOptions =>            {
                    serverOptions.Limits.MaxConcurrentConnections = 100;
                    serverOptions.Limits.MaxConcurrentUpgradedConnections = 100;
                    serverOptions.Limits.MaxRequestBodySize = 30 * 1024 * 1024;
                    serverOptions.Limits.MinRequestBodyDataRate =
                        new MinDataRate(bytesPerSecond: 100,
                            gracePeriod: TimeSpan.FromSeconds(10));
                    serverOptions.Limits.MinResponseDataRate =
                        new MinDataRate(bytesPerSecond: 100,
                            gracePeriod: TimeSpan.FromSeconds(10));
                    serverOptions.Limits.KeepAliveTimeout =
                        TimeSpan.FromMinutes(2);
                    serverOptions.Limits.RequestHeadersTimeout =
                        TimeSpan.FromMinutes(1);
                    serverOptions.Listen(IPAddress.Any, 5050);
                });
            })
            .UseAutofac()
            .UseWindowsService()
            .UseSerilog();
    

    Updated HttpApi.Host and DbMigrator appsettings.json related urls to http://localhost:5050 and ran the DbMigrator.

    Used the command dotnet publish -c Release -r win-x64 --self-containedunder HttpApi.Host project to publish.

    Before creating the service, I updated the appsettings.json under bin\release\..\publish; Redis configuration from 127.0.0.1 to localhost:6379 (since i run it on docker at port 6379) and Connection string to:

    "Default": "Server=localhost;Database=Tiered;User Id=sa;password=myPassW0rd!;MultipleActiveResultSets=true" since trusted_connection won't work.

    Creating and running windows service: Verified:

    Navigated to localhost:5050 and requested AbpApplicationConfiguration and  AbpApiDefinition:

    All seems working fine. Can you check the steps if something is different that may cause the problem?

  • User Avatar
    0
    can.ercan created

    You are right trusted_connection not working. User "Local System" cannot access db without sql user definition.

    We could not understand the problem because we could not see any error related to "DB connection" in the logs. We could not find the problem because we only saw the "Application is shutting down ..." log. This problem occurred because the Local System user could not access the db with "windows authentication". We were able to run the service by changing the Connection String.

    Thanks for detail response and help.

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Glad to hear your problem is solved.

    Closing the issue, please feel free to open a new one if you come across any other issues.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06