Using Postman to test .Net gRPC Service with SSL.

In this article I would like to describe how Postman can be used to test gRPC .Net service with the SSL support.

.Net gRPC Service

Simple .Net gRPC service can be created by following Microsoft article:
https://learn.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-7.0&tabs=visual-studio

Once service is created it uses self-signed certificate to support SSL in the dev environment. Which is great because SSL based end-points could be used during the development and testing.

Postman

I like to use the Postman for testing microservices during development - https://www.postman.com/.

It is a great tool and now has support for the gRPC protocol as well: https://blog.postman.com/postman-now-supports-grpc/

Using Postman to test service using http

Steps:

  1. Follow the article from Microsoft to create the GrpcGreeter service and run it.
  2. Run postman and create a new workspace and then a new collection.

3.  Now tricky moment: new grpc request can not be added by clicking 3 dots to the right of the collection

This will only add regular http request.

To add grpc request click on the new button on the Workspace level (in case if you missed this part in the Postman blog post):

Once you click it choose gRPC Request:


4. Because we are testing http endpoint first, enter the http endpoint from the running GrpcGreeter service (it is randomly assigned).

In my case it is 5150 port:

Notice this lock icon. It means that we are going to use http endpoint. I'll cover https in the next secton.

5. For the method name import the greet.proto file from the GrpcGreeter project, Protos folder.

Once you choose the greet.proto file, click 'Next' button in the Service definition tab.

6. In the next step you can either type name to create a new api (open dropdown):

or click 'Use without importing'

7.  And finally you can choose the method to call:

8.  Now if you click the Invoke button you should see the response like this:

{
	"message": "Hello "
}

You can also add message to send:

{
	"name":"test"
}

and you should get the following response:

{
	"message": "Hello test"
}

Using Postman to test service using https

Test project created above should automatically created a self-signed certificate issued to localhost. To call service using https the certificated should be:

  1. Exported using Certificate Manager (or MMC snap-in)
  2. Import certificate into Postman.

Export certificate

Select Run from the Start menu, and then enter certlm.msc

Open "Certificates - Local computer" -> "Personal" -> "Certificates"

Select localhost certificate -> right mouse click -> All tasks -> "Export"

It should open Certificate Export Wizard:

Choose yes to export private key.

And then select all default options:

On the next step choose the password for the exported certificate:

And then choose where to save the certificate:

Once you click finish the certificate should be exported.

Import certificate into Postman
Open postman. Go to Settings (top right corner)

Choose the Certificates tab

And click Add certificate.

Select just exported certificate for PFX file and enter the password you gave during the export.

Enter localhost for the host name:

Once you click Add certificate should be added to the postman. And the certificate tab should now have your certificate listed:

Calling gRPC service using https

To call gRpc service using https simply click on the lock near service address:

And if everything went well you should get a response from the service.