Testing grpc APIs

Hi Guys, I like to test gRPC as alternative to REST and JSON in my ServiceStack based servers, especially for mobile clients and server-to-server calls. However I am completely new to gRPC so I started ‘small’ by creating a new test project using x new rpc on a Fedora machine.

To test my REST APIs independent from a specific OS and language, I use Postman. I was looking for something similar for gRPC to test an API client / language independent. I found and like to try a tool called Kreya. It offers two ways to import information about provided services of a server:

And here I am already stuck! I started the test service and tried to import (without ssl) by entering the endpoint http://localhost:5054 in Kreya. The import request timed out or did not get any answer.

So the first question is: Does ServiceStack gRPC support server reflection and if so how can I use it?.

If it does not support it, how can I get the .proto files? I could not find them in the generated project. So do I have to use some tool to generate these files?

Hi @tbednarz,

The generated .proto file can be accessed at /types/proto which is listed in the docs page on gRPC. This works the same way as the other Add ServiceStack Reference tools.

Have a watch of our walk through on gRPC or checkout our docs for further reading, that might help you get comfortable with how gRPC works with ServiceStack.

Hope that helps!

hi @layoric
Thanks, tried the following without success:
Started the server on my Fedora VM and it looks like it is listening:

info: ProtoBuf.Grpc.Server.ServicesExtensions.CodeFirstServiceMethodProvider[0]
      RPC services being provided by GrpcServices: 6
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:5054
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://[::]:5051
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://[::]:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/tbednarz/Projects/Tests/MyGrpcTest/MyGrpcTest

Since I did NOT install any certificates I should be able to connect to port 5054 (insecure gRPC). So I installed the latest .NET 5 SDK on my Mac and installed the x tool afterwards.

Then I try to download those .proto files like so:
x --verbose csharp http://bsc-linuxdev:5054 test

I was able to connect to port 5054 using telnet, so it is not a firewall problem.

The result of the above call is:

args: 'csharp http://bsc-linuxdev:5054 test'
APP_SOURCE=sharp-apps Sharp Apps
API: http://bsc-linuxdev:5054/types/csharp
System.Net.Http.HttpRequestException: An error occurred while sending the request.
 ---> System.IO.IOException: The response ended prematurely.
   at System.Net.Http.HttpConnection.FillAsync(Boolean async)
   at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean async, Boolean foldedHeadersAllowed)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)

Any idea what is going wrong here?

Hi @tbednarz,

For x tooling, you should connect through standard HTTP/S endpoints, rather than the gRPC specific ones. gRPC endpoints require using a gRPC client which the x tool currently doesn’t support. ServiceStack hosts both gRPC and standard HTTP services side by side on different ports for maximum reuse/compatibility.

You can generate these types when running locally and just use the standard ASP.NET dev certificate setup, this way you can work locally on client and server at the same time and regenerate your client code as needed.

If you are having problems with macOS and ASPNET dev certificates I’d suggest locally hosting on plain HTTP to generate the client code or you can just share your ServiceModel project if both client/server are in your control and both in C#.

Hi @layoric

Thanks for that information. I wanted to avoid the generation of Certificates but it looks like there is no way around it. However it also looks gRPC is currently good for my server-to-server calls (instead of serializing / de-serializing all that data for every REST call). There all comms are http only since it is on an internal network.

Looks like gRPC is hard to use from outside, since Browsers do not fully support HTTP/2 and you have to work with tools like gRPC-Web. Also we use HAproxy a lot and our encryption ends there. It is no fun to manage certificates in dozens of docker containers, so internal comms are always un-encrypted. It looks like gRPC and HTTP/2 also requires specialized newer proxies such as Envoy.

So a production ready use of gRPC seems to require a lot of changes and also relatively new software in the entire tool-chain… Definitely something to keep an eye on, but nothing that can be used quickly, there are too many new components involved. We will start with it in server-to-server comms to get familiar with it. When reading the ServiceStack docs it looks like gRPC comms between ServiceStack based servers is not too complicated but more efficient than REST/JSON and has the advantage of being strongly typed.

1 Like