question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implementing a grpc server in .net standard class library

See original GitHub issue

How 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
hawkermcommented, Oct 21, 2021

It doesn’t make a difference. A gRPC server app needs a server to run on. ASP.NET Core gives you the choice of Kestrel/IIS/HTTP.sys.

I don’t think that will work in UWP. UWP won’t have all the APIs required to host a website (sockets, TLS, etc)

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.

10reactions
JamesNKcommented, Sep 20, 2021

You can’t. Grpc.AspNetCore requires ASP.NET Core.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found