JSON-RPC in ASP.NET Core With StreamJsonRpc

25 cze 2020 | Blog | asp.net core | json-rpc | IT

I've been pointed to StreamJsonRpc library through a comment under one of my posts and I've decided it's something worth taking a look at. StreamJsonRpc is a .NET Standard implementation of JSON-RPC 2.0 wire protocol.

The question that probably comes to your mind right now is why one should spend time to take a look at yet another RPC technology? After all ASP.NET Core already has SignalR and gRPC (I would like to add RSocket to that list but at this point, it looks like the .NET implementation is going nowhere). Well, SignalR doesn't have a nice way to perform an invocation and receive a response from it. gRPC has very specific requirements regarding transport. gRPC-Web improves that and its ASP.NET Core implementation is very nice, but it's still not perfect. In this context, JSON-RPC 2.0 provides simple invocations with support for responses and is transport agnostic. The .NET implementation will happily work with Stream, WebSocket, or IDuplexPipe. There are also some very nice additions like out-of-the-box support for IProgress and IAsyncEnumerable.

Because of how flexible StreamJsonRpc is when it comes to the underlying transport, there are two main options for hosting it in an ASP.NET Core application.

Standalone Service Using IDuplexPipe

The first option is to use networking primitives for non-HTTP Servers and build a standalone service providing JSON-RPC over TCP on top of bare Kestrel.

Let's assume this will be our server (any similarity to a gRPC sample is totally intended).

public class HelloRequest
{
public string Name { get; set; }
}

public class HelloReply
{
public string Message { get; set; }
}

publi

POSTY TEGO AUTORA

Monitoring C# Azure Functions in the Isolated Worker Model - Infrastructure & Configuration Deep Dive26 lis 2024

Blog | programowanie | .net | c# | azure functions | IT

ASP.NET Core 9 and IAsyncEnumerable - Async Streaming JSON and NDJSON From Blazor WebAssembly24 wrz 2024

Blog | programowanie | .net | c# | asp.net core | blazor | IT

Azure Functions Extensibility - Extensions and Isolated Worker Model5 mar 2024

Blog | programowanie | .net | c# | azure functions | azure | IT

Azure Functions Extensibility - Runtime Scaling22 lut 2024

Blog | programowanie | .net | c# | azure | IT

Yet Another Developer Blog

noreply@blogger.com (Tomasz Pęczek)