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 at Converge 360.

comments powered by Disqus

Featured

  • Microsoft Revamps Fledgling AutoGen Framework for Agentic AI

    Only at v0.4, Microsoft's AutoGen framework for agentic AI -- the hottest new trend in AI development -- has already undergone a complete revamp, going to an asynchronous, event-driven architecture.

  • IDE Irony: Coding Errors Cause 'Critical' Vulnerability in Visual Studio

    In a larger-than-normal Patch Tuesday, Microsoft warned of a "critical" vulnerability in Visual Studio that should be fixed immediately if automatic patching isn't enabled, ironically caused by coding errors.

  • Building Blazor Applications

    A trio of Blazor experts will conduct a full-day workshop for devs to learn everything about the tech a a March developer conference in Las Vegas keynoted by Microsoft execs and featuring many Microsoft devs.

  • Gradient Boosting Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the gradient boosting regression technique, where the goal is to predict a single numeric value. Compared to existing library implementations of gradient boosting regression, a from-scratch implementation allows much easier customization and integration with other .NET systems.

  • Microsoft Execs to Tackle AI and Cloud in Dev Conference Keynotes

    AI unsurprisingly is all over keynotes that Microsoft execs will helm to kick off the Visual Studio Live! developer conference in Las Vegas, March 10-14, which the company described as "a must-attend event."

Subscribe on YouTube