How to change port and enable https for hosted web api inside a worker service

193 Views Asked by At

I have an WorkerService and inside it we would like to host web api.

For the WebApi we need to change the ports where to listen to.

How can this be done? For now I used the UseUrls, is it ok?

How to enable https on it? If I put an https url it doesn't work.

Below the code used for now.

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .Enrich.FromLogContext()
    .WriteTo.File("D:\\Logs\\logs.txt")
    .CreateLogger();

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseUrls(new string[] { "http://*:8888" });

builder.Host.UseWindowsService(options =>
{
    options.ServiceName = ".NET Joke Service With API";
});

builder.Host.UseSerilog();

builder.Services.AddSingleton<RabbitMQService>();

builder.Services.AddSingleton<WindowsBackgroundService>();
builder.Services.AddHostedService<WindowsBackgroundService>(provider => provider.GetService<WindowsBackgroundService>());
builder.Services.AddControllers();
0

There are 0 best solutions below