News

Experimental ASP.NET Core Support for gRPC-Web Allows Remote Procedure Calls from Browser

Microsoft officially introduced ASP.NET Core experimental support for gRPC-Web, which allows Google's remote procedure call (RPC) tech to work in browser-based web applications, something not previously possible.

The new functinality is key to Microsoft's ASP.NET Core and Blazor initiatives, with gRPC acting 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, the web development component. Blazor has gained attention for its ability to let .NET coders do web development with C# or F# instead of JavaScript, which is used in just about every other web-dev scheme.

gRPC-Web isn't new, and has been featured in previous presentations such as this one by Blazor guru Steve Sanderson in a recent online event, which showed how a Blazor WebAssembly app (the client-side Blazor component) could use gRPC. In that scenario, gRPC was used as a substitute for transporting JSON data over the wire.

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

However, in today's (Jan. 27) official introduction, gRPC-Web is touted for other benefits, including:

  • Strongly-typed code-generated clients
  • Compact Protobuf messages
  • Server streaming

The gRPC web site on GitHub says:

gRPC-Web provides a JS client library that supports the same API as gRPC-Node to access a gRPC service. Due to browser limitation, the Web client library implements a different protocol than the native gRPC protocol. This protocol is designed to make it easy for a proxy to translate between the protocols as this is the most likely deployment model.

Today's post by James Newton-King, principal software engineer, ASP.NET, provides more intormation on those protocols.

"It is impossible to implement the gRPC HTTP/2 spec in the browser because there is no browser API with enough fine-grained control over HTTP requests," Newton-King explained. "gRPC-Web solves this problem by being compatible with HTTP/1.1 and HTTP/2.

"gRPC-Web is not a new technology. There is a stable gRPC-Web JavaScript client, and a proxy for translating between gRPC and gRPC-Web for services. The new experimental packages allow an ASP.NET Core gRPC app to support gRPC-Web without a proxy, and allow the .NET Core gRPC client to call gRPC-Web services. (great for Blazor WebAssembly apps!)"

That will result in new opportunities 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 – Some .NET platforms HttpClient doesn't support HTTP/2. gRPC-Web can be used to call gRPC services on these platforms (e.g. Blazor WebAssembly, Xamarin).

However, some caveats to consider when using the new gRPC-Web include "a small performance cost" and the ending of support for client streaming and bi-directional streaming, though server streaming is still supported.

A wealth of information is available for the new initiative, including:

Also, Visual Studio Magazine writer Peter Vogel has been focusing on gRPC lately with these aritcles:

In the meantime, Newton-King and the rest of the ASP.NET Core team are dipping gRPC-Web's toes into the .NET development waters to see how it's received.

"gRPC-Web for .NET is an experimental project, not a committed product," he said. "We want to test that our approach to implementing gRPC-Web works, and get feedback on whether this approach is useful to .NET developers compared to the traditional way of setting up gRPC-Web via a proxy. Please add your feedback here or at the https://github.com/grpc/grpc-dotnet to ensure we build something that developers like and are productive with."

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