Created
March 3, 2021 21:06
-
-
Save anlsh/20b41d9ca5aa7f9c84a6c05e1722d7fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Startup.cs | |
public class Startup { | |
public void ConfigureServices(IServiceCollection services) { | |
services.AddGrpc(); | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
app.UseRouting(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapGrpcService<GreeterService>(); | |
}); | |
} | |
} | |
// Program.cs | |
public class Program | |
{ | |
public static void Main(string[] args) { | |
CreateHostBuilder(args).Build().Run(); | |
} | |
public static X509Certificate2 GetCert() { | |
// Retrieve a cert from the local windows store | |
} | |
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder.ConfigureKestrel(options => | |
{ | |
options.ListenAnyIP(50052, o => { | |
var cert = Program.GetCert(); | |
o.UseHttps(cert); | |
o.Protocols = HttpProtocols.Http2; | |
}); | |
}); | |
webBuilder.UseStartup<Startup>(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment