News

Move Over, JSON, Here's gRPC-Web for .NET (& Blazor)

Microsoft officially released gRPC-Web for .NET, aiming the RPC-based (Remote Procedure Call) framework at browser-based apps, including those built with Blazor, the red-hot project that allows for creating browser/web apps with C# instead of JavaScript.

Now a fully supported component of the grpc-dotnet project, it allows for browser-based use of gRPC, an open standard based on HTTP/2 -- which doesn't work well on some .NET components -- and other modern technologies.

It can act as a substitute for Windows Communication Foundation (WCF) technology that didn't make the transition from the old, Windows-only .NET Framework to the new open-source, crosss-platform "Core" direction that encompasses .NET Core along with ASP.NET Core.

What's more, it serves as a substitute for JSON, with better performance.

"We've worked with the Blazor team to make gRPC-Web a great end-to-end developer experience when used in Blazor WebAssembly apps," Microsoft's James Newton-King, principal software engineer, ASP.NET, said in a June 16 blog post. "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."

 Data transferred on the Blazor default template app's Fetch page is halved when gRPC is used instead of JSON. Data size is reduced from 627 bytes down to 309 bytes.
[Click on image for larger view.] Data transferred on the Blazor default template app's Fetch page is halved when gRPC is used instead of JSON. Data size is reduced from 627 bytes down to 309 bytes. (source: Microsoft).

gRPC-Web for .NET was needed for Blazor and other projects because browsers don't have APIs to to adequately control gRPC HTTP/2 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."

Those features are now production-ready, allowing for new coding scenarios including:

  • 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.

Blazor guru Steve Sanderson early this year detailed how gRPC fits into the company's plans for Blazor, about the same time Microsoft officially introduced ASP.NET Core experimental support for gRPC-Web. Since then, using feedback from early adopters, Microsoft has improved the product now generally available for production use.

Blazor gRPC
[Click on image for larger view.] Early documentation for Blazor gRPC (source: Microsoft).

Resources for more information include:

gRPC also was a focal point of Visual Studio Magazine writer Peter Vogel, who wrote the following articles for more information.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube