gRPC-Web for .NET now available

James Newton-King

gRPC-Web for .NET is now officially released. We announced experimental support in January and since then we’ve been making improvements based on feedback from early adopters.

With this release gRPC-Web graduates to a fully supported component of the grpc-dotnet project and is ready for production. Use gRPC in the browser with gRPC-Web and .NET today.

Getting started

Developers who are brand new to gRPC should check out Create a gRPC client and server in ASP.NET Core. This tutorial walks through creating your first gRPC client and server using .NET.

If you already have a gRPC app then the Use gRPC in browser apps article shows how to add gRPC-Web to a .NET gRPC server.

What are gRPC and gRPC-Web

gRPC is a modern high-performance RPC (Remote Procedure Call) framework. gRPC is based on HTTP/2, Protocol Buffers and other modern standard-based technologies. gRPC is an open standard and is supported by many programming languages, including .NET.

It is currently impossible to implement the gRPC HTTP/2 spec in the browser because there are no browser APIs with enough fine-grained control over requests. gRPC-Web is a standardized protocol that solves this problem and makes gRPC usable in the browser. gRPC-Web brings many of gRPC’s great features, like small binary messages and contract-first APIs, to modern browser apps.

New opportunities with gRPC-Web

gRPC-Web is designed to make gRPC available in more scenarios. These include:

  • Call ASP.NET Core gRPC apps from the browser – Browser APIs can’t call gRPC HTTP/2. gRPC-Web offers a compatible alternative.
    • JavaScript SPAs
    • .NET Blazor Web Assembly apps
  • Host ASP.NET Core gRPC apps in IIS and Azure App Service – Some servers, such as IIS and Azure App Service, currently can’t host gRPC services. While this is actively being worked on, gRPC-Web offers an interesting alternative that works in every environment today.
  • Call gRPC from non-.NET Core platforms – HTTP/2 is not supported by HttpClient on all .NET platforms. gRPC-Web can be used to call gRPC services from Blazor and Xamarin.

gRPC loves Blazor and .NET

gRPC is a registered trademark of the Linux foundation. Blazor is compatible with gRPC-web

We’ve worked with the Blazor team to make gRPC-Web a great end-to-end developer experience when used in Blazor WebAssembly apps. Not only will gRPC tooling automatically generate strongly typed clients for you to call gRPC services from your Blazor app, but gRPC offers significant performance benefits over JSON.

A great example of the performance benefits in action is Blazor’s default template app. The data transferred on the fetch data page is halved when gRPC is used instead of JSON. Data size is reduced from 627 bytes down to 309 bytes.

Developer tools showing gRPC-Web transfer size

The performance gain here comes from gRPC’s efficient binary serialization over traditional text-based JSON. gRPC-Web is an exciting opportunity to improve rich browser-based apps.

Try gRPC-Web with ASP.NET Core today

For more information about gRPC-Web, check out the documention, or try out a sample app that uses gRPC-Web.

gRPC-Web for .NET is out on NuGet now:

We look forward to seeing what you create with .NET, gRPC and now gRPC-Web!

29 comments

Discussion is closed. Login to edit/delete existing comments.

  • haroon shah 0

    Wondering if the limitation of gRPC running on Azure/IIS has been fixed? thanks

    • James Newton-KingMicrosoft employee 0

      Work on that is ongoing and I don’t have an update. However gRPC-Web is an alternative compatible with Azure/IIS that you can use today.

      • Herb Stahl 0

        Has anyone proved a deployment to azure AppService. I get it working locally, and am seeing grpc-web-text

        Solution: I used the gRPC starter project which put the following in appSettings.json.

          "Kestrel": {
            "EndpointDefaults": {
              "Protocols": "Http2"
            }
          }

        Remove that and things start working. I can deploy to Azure AppService.

        If you don’t, you will get the following errors;

        info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
              Executing endpoint 'gRPC - /fluffybunny4.ClientStore/GetClients'
        info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
              Executed endpoint 'gRPC - /fluffybunny4.ClientStore/GetClients'
        info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
              Request finished in 5.9713ms 200 application/grpc-web-text

        I have been getting varying errors.

        Grpc.Core.RpcException: 'Status(StatusCode=Unavailable, Detail="Bad gRPC response. HTTP status code: 503")'

        and some “Not implemented” exception.
        The code I am using from my test console app is stuff I found in the blazor example.

                    var channel = GrpcChannel.ForAddress(grpcServer, new GrpcChannelOptions { HttpHandler = httpHandler });
                    var client = new Fluffybunny4.ClientStore.ClientStoreClient(channel);
                    var greeterClient = new Greeter.GreeterClient(channel);
                    await UnaryCallGreeter(greeterClient);
  • Christian Sparre 0

    Great work, I really like working with gRPC services. But would really have liked to write some of our services using gRPC, but as we are hosting those in Azure we need gRPC-Web, so we can’t actually access those services from our older .NET Framework based systems as the Grpc.Net.Client.Web package depends on netstandard2.1 😥

    So maybe you should be referring to it as gRPC-Web for .NET Core instead?

    • Henrich Horvath 0

      next update of .NET Core will be named just “.NET 5” so I they probably already use this naming

    • AlseinX 0

      I don’t think the naming of a new technology should respect a deprecated framework.

  • Paulo Roberto Elias 0

    Nice post. Thanks for sharing

  • Sander in 't Hout 0

    I am currently using vs-streamjsonrpc running on top of a WebSocket connection for my RPC needs. Will gRPC-web be able to run over WebSockets in the near future?

    This could make an application way more responsive if it does a lot of calls to my hosted service.

    • James Newton-KingMicrosoft employee 0

      Some gRPC-Web clients support websockets. The .NET gRPC-Web client uses HTTP and there are no plans for websockets.

  • Lars 0

    Great article. I have two questions about your performance statement (“The data transferred on the fetch data page is halved when gRPC is used instead of JSON.”) Is that true even for 1. big json objects 2. gzipped versions of json / gRPC. This might be a common gRPC question, but I thought I ask since you brought it up 😉

    • James Newton-KingMicrosoft employee 0

      Size difference will depend on the data being sent.

      For example, strings in JSON and Protobuf (serialization format used by gRPC) are both UTF8, so are the same size. Meanwhile dates in Protobuf are sent as high precision tickets, which is significantly smaller than JSON’s ISO date format.

  • Leo Lloyd Andrade 0

    Great news. Thanks Msft for the efforts. couple of questions, how is this client different from grpc-web that uses an intermediary envoy proxy. Also how does it stack up against SignalR, both in terms of performance and ease of usage.

    • James Newton-KingMicrosoft employee 0

      gRPC-Web for .NET translates gRPC-Web to gRPC in the .NET server. It is just another middleware. Meanwhile Envoy is a separate proxy.

      I don’t have performance numbers of gRPC vs SignalR. I suspect SignalR can send and receive messages faster than gRPC because it has its own simplified protocol, but SignalR has server overhead to track connections.

  • Craig Johnson 0

    Fabulous stuff. Curious if the compression on the Blazor side is now operational, and, if it is, what the pattern might look like

                    var compressionproviders = new List();
    
                    compressionproviders.Add(new GzipCompressionProvider(System.IO.Compression.CompressionLevel.Optimal));
    
                    var channel = GrpcChannel.ForAddress("https://localhost:2494", new GrpcChannelOptions { HttpClient = httpClient, CompressionProviders = compressionproviders });
    
    • James Newton-KingMicrosoft employee 0

      Compression in Blazor is supported. It works exactly the same way compression does with a .NET gRPC client on .NET Core.

  • Kitty Quinn 0

    Can this be generically used with any js client like protobuf.js in a spa scenario?

  • Metro Sauper 0

    Is there any hope for a .Net Standard 2.0 compatible gRPC client so we can develop new services using .Net Core but allow them to be consumed by our older .Net Framework apps?

    • James Newton-KingMicrosoft employee 0

      You will need to use Grpc.Core.

      HttpClient in .NET Framework doesn’t support HTTP/2 and there are no plans to add it.

      • Metro Sauper 0

        Isn’t the fact that HttpClient in .Net Framework doesn’t support HTTP/2 the same problem as the browser not supporting it? Wouldn’t the gRpc-Web solution work for .Net Framework also?

        • James Newton-KingMicrosoft employee 0

          It is possible to create a grpc-web client for .NET Framework. In our case, Grpc.Net.Client uses netstandard2.1 specific APIs as part of its support for regular gRPC over HTTP/2. Supporting netstandard2.0 is not possible.

  • AndreaG 0

    Is possible to call gRPC services from a Xamarin Forms app? I didn’t find any specific code example for xamarin. Trying to setting up locally a gRPC-Web server and a Xamarin Forms app, I’m not able to call the service from the Android emulator. I followed the documentation (after successfully made the intro gRPC tutorial) and I have also considered how to connect to local web services from emulator. Thanks

Feedback usabilla icon