Lakerfield.Rpc.WebSocketClient 1.0.2

Prefix Reserved
dotnet add package Lakerfield.Rpc.WebSocketClient --version 1.0.2
                    
NuGet\Install-Package Lakerfield.Rpc.WebSocketClient -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lakerfield.Rpc.WebSocketClient" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lakerfield.Rpc.WebSocketClient" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Lakerfield.Rpc.WebSocketClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lakerfield.Rpc.WebSocketClient --version 1.0.2
                    
#r "nuget: Lakerfield.Rpc.WebSocketClient, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lakerfield.Rpc.WebSocketClient@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lakerfield.Rpc.WebSocketClient&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Lakerfield.Rpc.WebSocketClient&version=1.0.2
                    
Install as a Cake Tool

Lakerfield.Rpc

Lakerfield.Rpc is a flexible RPC implementation for .NET, enabling remote procedure calls over WebSockets (with optional TCP support) using BSON for message serialization via the MongoDB.Bson / Lakerfield.Bson library.

Features

  • Define a single interface to represent your RPC contract; source generators automatically generate all client and server code based on that interface
  • Supports WebSocket transport (TCP support available)
  • Compact, binary messages with BSON serialization

Requirements

  • .NET 8.0 or higher

Installation

Install the core RPC library:

dotnet add package Lakerfield.Rpc
dotnet add package Lakerfield.Rpc.SourceGenerator

Install the client RPC libary:

dotnet add package Lakerfield.Rpc.SourceGenerator
dotnet add package Lakerfield.Rpc.WebSocketClient

Install the server RPC libary:

dotnet add package Lakerfield.Rpc.SourceGenerator
dotnet add package Lakerfield.Rpc.WebSocketServer

Dependencies

  • Lakerfield.Bson: A fork of MongoDB.Bson (with only a namespace change) to avoid conflicts when using MongoDB.Bson in your application, used for efficient BSON serialization.
  • System.Reactive: Required by both WebSocket client and server for reactive message handling.
  • Microsoft.AspNetCore.App: Framework reference for the WebSocket server.

Usage Example (WebSocket)

Shared libary with the interface and bson configuration

[RpcService]
public interface IRpcTestService
{
  Task<Company> CompanyFindById(Guid id);
}

public static partial class RpcTestServiceBsonConfigurator
{
  static partial void PreConfigure()
  {
    // configure bson mapping of the models
    Lakerfield.Bson.Serialization.BsonClassMap.RegisterClassMap<Models.Company>(AutoMap);
  }
}

WebSocket Client

var networkClient = new NetworkClient(new Uri("ws://localhost/ws"));
var client = new RpcTestServiceClient(networkClient);

var company = await client.CompanyFindById(Guid.NewGuid());
[RpcClient]
public partial class RpcTestServiceClient : IRpcTestService
{
  // implementation is generated by sourcegenerator
}

WebSocket Server

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRpcWebSocketServer<IRpcTestService, RpcTestWebSocketServiceServer>();

var app = builder.Build();

app.UseWebSockets(new WebSocketOptions
{
  KeepAliveInterval = TimeSpan.FromSeconds(120),
  AllowedOrigins = { "*" } // Pas dit aan voor productie!
});
app.UseRpcWebSocketServer<IRpcTestService>("/ws");

await app.RunAsync();
[RpcServer]
public partial class RpcTestWebSocketServiceServer : Lakerfield.Rpc.LakerfieldRpcWebSocketServer<IRpcTestService>
{
  public override ILakerfieldRpcClientMessageHandler CreateConnectionMessageRouter(LakerfieldRpcWebSocketServerConnection connection)
  {
    return new ClientConnectionMessageHandler(connection as LakerfieldRpcWebSocketServerConnection<IRpcTestService>);
  }

  public partial class ClientConnectionMessageHandler // implements IRpcTestService
  {
    public async Task<Models.Company> CompanyFindById(System.Guid id)
    {
      return new Models.Company()
      {
        Id = id.ToString(),
        Name = "The company",
      };
    }
}

Example Project

See the complete WebSocket demo in the RpcDemo projects of the rosacode repository:

https://github.com/Lakerfield/rosacode

Contributing

Contributions, issues, and feature requests are welcome. Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 244 11/14/2025
1.0.1 293 11/12/2025
1.0.0 277 11/12/2025
1.0.0-rc.6 146 10/23/2025
1.0.0-rc.5 137 10/23/2025
1.0.0-rc.4 140 10/20/2025
1.0.0-rc.3 74 10/17/2025
1.0.0-rc.2 136 10/15/2025
1.0.0-rc.1 144 10/13/2025
1.0.0-beta.7 172 4/10/2025