Implementing a grpc server in .net standard class library
See original GitHub issueHow can I implement a server using grpc-dotnet in a class library like we used to implement in earlier versions??
using System;
using System.Threading.Tasks;
using Grpc.Core;
using Helloworld;
namespace GreeterServer
{
class GreeterImpl : Greeter.GreeterBase
{
// Server side handler of the SayHello RPC
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
{
return Task.FromResult(new HelloReply { Message = "Hello " + request.Name });
}
}
class TestServer
{
const int Port = 30051;
public TestServer()
{
Server server = new Server
{
Services = { Greeter.BindService(new GreeterImpl()) },
Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
};
server.Start();
Console.WriteLine("Greeter server listening on port " + Port);
}
~TestServer()
{
server.ShutdownAsync().Wait();
}
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Use gRPC client with .NET Standard 2.0
Learn how to use the .NET gRPC client in apps and libraries that support .NET Standard 2.0.
Read more >Tutorial: Create a gRPC client and server in ASP.NET Core
This tutorial shows how to create a gRPC Service and gRPC client on ASP.NET Core. Learn how to create a gRPC Service project,...
Read more >Creating gRPC .NET Core Client Libraries - Code with Steve
In this post, I want to demonstrate how we can quickly and easily create a shared class library which includes the auto-generated gRPC...
Read more >c# - Grpc client in .net standard fails when called from . ...
I use this for testing error handling in the clients - I can control which responses the server gives. I implemented two exactly...
Read more >ServiceModel.Grpc Create a gRPC client and server in ...
View sample code. Create a contract first. Create a blank solution. Add new “Class Library (.NET standard)” project with name “Contract”.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Right, why is my RPC service requiring a website in order to function? The need to serve via a web host doesn’t seem to be required with other languages. I just want to open a port to have a server to listen to the protocol on to act as my server and use gRPC instead of traditional networking code.
UWP can generally host sockets and other things just limits connects to/from the local machine. Anyway, the same question would apply to a WinUI 3 app that’s running on .NET 5+ too.
You can’t. Grpc.AspNetCore requires ASP.NET Core.