Earlier we were using .net core 2.1 API, In the same Project we were exposing two ports, One for rest API and another one for GRPC
Below is how our startup and Program file looks like
Startup file
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//Proces for GRPC server binding
Server server = new Server
{
Services = { HealthCheck.BindService(new HealthCheckController()),
},
Ports = { new ServerPort("0.0.0.0", 5001, ServerCredentials.Insecure) }
};
//Start GRPC server
server.Start();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
Program file
public static class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
}
}
Now we want to migrate the same project to .net core 3.1, and want to maintain two seprate ports, one for GRPC and other one for rest API
Below is how our startup and Program file looks like
Startup file
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<HealthCheckController>();
endpoints.MapControllers();
});
//Start GRPC server
}
Program file
public static class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
But the problem is after migrating to .net core 3.1 we are only able to use both the services on the same port, any help on how we can separate ports for GRPC and Rest API is appreciated.