Last active
August 14, 2019 23:10
-
-
Save mustakimali/29510470ee1a1dba6938644d00ecdef9 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
using System.Net; | |
using System.Threading.Tasks; | |
using Google.Protobuf.WellKnownTypes; | |
using Grpc.Core; | |
using GrpcDotNetDemoPackage; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Server.Kestrel.Core; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
namespace Server | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
CreateHostBuilder(args).Build().Run(); | |
} | |
public static IHostBuilder CreateHostBuilder(string[] args) | |
{ | |
return Host | |
.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => | |
{ | |
webBuilder | |
.ConfigureKestrel(c => | |
{ | |
// we will update the following line later to enable SSL | |
// Note: TLS with HTTP/2 isn't supported in mac | |
// Wait for next version of macOS | |
c.Listen(IPEndPoint.Parse("0.0.0.0:5000"), l => l.Protocols = HttpProtocols.Http2); | |
}) | |
.UseStartup<Startup>(); | |
}); | |
} | |
} | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddGrpc(); | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseRouting(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapGrpcService<DemoServiceImpl>(); | |
}); | |
} | |
} | |
public class DemoServiceImpl : DemoService.DemoServiceBase | |
{ | |
public override Task<HelloResponse> SayHello(HelloRequest request, ServerCallContext context) | |
{ | |
return Task.FromResult(new HelloResponse | |
{ | |
Hello = $"Hello {request.Name}" | |
}); | |
} | |
public override Task<HelloResponse> SayHelloToNobody(Empty request, ServerCallContext context) | |
{ | |
return Task.FromResult(new HelloResponse | |
{ | |
Hello = "Hello Nobody!" | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment