Created
March 3, 2021 21:05
-
-
Save anlsh/4ede23f943bfd22aca9af2244a0daace 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