Sphere10.Framework.Communications 3.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sphere10.Framework.Communications --version 3.0.2
                    
NuGet\Install-Package Sphere10.Framework.Communications -Version 3.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="Sphere10.Framework.Communications" Version="3.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sphere10.Framework.Communications" Version="3.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Sphere10.Framework.Communications" />
                    
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 Sphere10.Framework.Communications --version 3.0.2
                    
#r "nuget: Sphere10.Framework.Communications, 3.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 Sphere10.Framework.Communications@3.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=Sphere10.Framework.Communications&version=3.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Sphere10.Framework.Communications&version=3.0.2
                    
Install as a Cake Tool

๐Ÿ“ก Sphere10.Framework.Communications

Multi-protocol networking and RPC framework for .NET 8.0+ providing type-safe remote procedure calls, protocol abstraction, and distributed system communication patterns.

Sphere10.Framework.Communications enables seamless remote service invocation through attribute-based RPC definitions with automatic JSON serialization, type conversion, and protocol agnosticism.

โšก 10-Second Example

using Sphere10.Framework.Communications.RPC;
using System.Text;

// Define RPC service with attributes
[RpcAPIService("calculator")]
public class CalcService {
    [RpcAPIMethod]
    public int Add(int a, int b) => a + b;
    
    [RpcAPIMethod]
    public string Greet([RpcAPIArgument("name")] string userName) 
        => $"Hello, {userName}!";
}

// Invoke remotely (framework handles serialization)
var result = await rpcClient.InvokeAsync<int>("calculator.Add", new { a = 5, b = 3 });
Console.WriteLine(result);  // 8

var greeting = await rpcClient.InvokeAsync<string>("calculator.Greet", new { name = "World" });
Console.WriteLine(greeting);  // "Hello, World!"

๐Ÿ—๏ธ Core Concepts

RPC Service: Method marked with [RpcAPIService] and [RpcAPIMethod] attributes that can be invoked remotely.

Method Parameters: Parameters automatically serialized from JSON with support for primitives, objects, collections, and enums.

Type-Safe Invocation: Call remote methods as if they were local, with automatic serialization and deserialization.

Protocol Agnostic: RPC framework separates protocol implementation from service definitionโ€”swap transports without changing service code.

Custom Naming: Use [RpcAPIArgument("name")] to map C# parameter names to JSON field names for API flexibility.

๐Ÿ”ง Core Examples

Primitive Type Services

using Sphere10.Framework.Communications.RPC;

// Define RPC service with multiple primitive type methods
[RpcAPIService("math")]
public class MathService {
    [RpcAPIMethod]
    public int Add(int a, int b) => a + b;
    
    [RpcAPIMethod]
    public uint AddUnsigned(uint a, uint b) => a + b;
    
    [RpcAPIMethod]
    public float Multiply(float a, float b) => a * b;
    
    [RpcAPIMethod]
    public double Divide(double a, double b) => a / b;
    
    [RpcAPIMethod]
    public string Concatenate(string a, string b) => a + b;
    
    [RpcAPIMethod]
    public bool IsGreater(int a, int b) => a > b;
}

// JSON-RPC invocation format:
// {"jsonrpc": "2.0", "method": "math.Add", "params": {"a": 5, "b": 3}, "id": 1}
// Response: {"jsonrpc": "2.0", "result": 8, "id": 1}

Custom Parameter Naming

using Sphere10.Framework.Communications.RPC;

// Use [RpcAPIArgument] to map C# names to JSON field names
[RpcAPIService("strings")]
public class StringService {
    [RpcAPIMethod]
    public string Concat(
        [RpcAPIArgument("first")] string text1,
        [RpcAPIArgument("second")] string text2) 
        => text1 + text2;
    
    [RpcAPIMethod]
    public int MixedTypes(
        [RpcAPIArgument("num")] int number,
        [RpcAPIArgument("text")] string str) 
        => number + str.Length;
}

// JSON-RPC invocation:
// {"jsonrpc": "2.0", "method": "strings.Concat", 
//  "params": {"first": "Hello", "second": "World"}, "id": 1}
// Response: {"jsonrpc": "2.0", "result": "HelloWorld", "id": 1}

Complex Objects & Collections

using Sphere10.Framework.Communications.RPC;
using System.Collections.Generic;
using System.Text.Json.Serialization;

// Define complex types for RPC parameters
public class Person {
    public string Name { get; set; }
    public int Age { get; set; }
    public string[] Tags { get; set; }
}

[RpcAPIService("people")]
public class PeopleService {
    [RpcAPIMethod]
    public string GetInfo(Person person) 
        => $"{person.Name} is {person.Age}, tags: {string.Join(",", person.Tags)}";
    
    [RpcAPIMethod]
    public int CountTags(Person person) 
        => person.Tags?.Length ?? 0;
    
    [RpcAPIMethod]
    public List<Person> FilterByAge(List<Person> people, int minAge) 
        => people.FindAll(p => p.Age >= minAge);
}

// JSON-RPC invocation:
// {"jsonrpc": "2.0", "method": "people.GetInfo", 
//  "params": {"person": {"name": "Alice", "age": 30, "tags": ["dev", "blockchain"]}}, "id": 1}

Enum Serialization

using Sphere10.Framework.Communications.RPC;

public enum Status { Active = 1, Inactive = 2, Pending = 3 }

[RpcAPIService("status")]
public class StatusService {
    [RpcAPIMethod]
    public string GetStatusName(Status status) => status.ToString();
    
    [RpcAPIMethod]
    public bool IsActive(Status status) => status == Status.Active;
    
    [RpcAPIMethod]
    public Status[] GetAllStatuses() => new[] { Status.Active, Status.Inactive, Status.Pending };
}

// JSON-RPC supports both numeric and string enum representation
// {"jsonrpc": "2.0", "method": "status.IsActive", "params": {"status": "Active"}, "id": 1}
// or
// {"jsonrpc": "2.0", "method": "status.IsActive", "params": {"status": 1}, "id": 1}

Byte Array Handling

using Sphere10.Framework.Communications.RPC;
using System.Text.Json.Serialization;

public class DataPayload {
    public string Name { get; set; }
    [JsonPropertyName("data_hex")]
    public byte[] Data { get; set; }  // Serialized as hex string in JSON
}

[RpcAPIService("data")]
public class DataService {
    [RpcAPIMethod]
    public int GetLength(DataPayload payload) 
        => payload.Data?.Length ?? 0;
    
    [RpcAPIMethod]
    public string GetDataHash(DataPayload payload) 
        => Tools.Hashing.SHA256Hex(payload.Data);
}

// JSON-RPC invocation with hex-encoded bytes:
// {"jsonrpc": "2.0", "method": "data.GetLength", 
//  "params": {"payload": {"name": "test", "data_hex": "0102030405"}}, "id": 1}
// Response: {"jsonrpc": "2.0", "result": 5, "id": 1}

๐ŸŽฏ Service Registration & Discovery

Services are automatically discovered via reflection from assemblies containing [RpcAPIService] attributes. The framework builds a method registry mapping RPC method names (service.method) to implementations.

Service Namespace: [RpcAPIService("namespace")] organizes methods under a namespace for API organization.

Method Overloading: Not supported in RPC due to JSON-based parameter passing; use different method names or combine parameters into complex types.

๐Ÿ”Œ Protocol Abstraction

The RPC framework is protocol-agnostic:

  • Transport: Pluggable transport layer (HTTP, WebSocket, TCP, named pipes)
  • Serialization: JSON by default; can implement IMessageSerializer for alternatives
  • Message Format: JSON-RPC 2.0 compatible request/response structure

Services defined with attributes work unchanged across different transport implementations.

๐Ÿ—๏ธ Architecture

  • RPC Service Definition: [RpcAPIService], [RpcAPIMethod], [RpcAPIArgument] attributes
  • Service Registry: Automatic discovery and method registration
  • Parameter Binding: JSON โ†’ C# object conversion with type safety
  • Response Serialization: C# return values โ†’ JSON
  • Protocol Handlers: Transport-specific implementations (HTTP, WebSocket, etc.)

๐Ÿ› ๏ธ Tools.* Namespace

This project does not define project-specific Tools classes. Refer to related projects:

โš ๏ธ Design Considerations

  • Stateless Services: Design services as stateless when possible for distributed invocation
  • Exception Handling: Exceptions are serialized and returned as JSON-RPC error responses
  • Parameter Validation: Validate parameters in service methods; null checks recommended
  • Return Type Support: Primitive types, objects, collections, enums, byte arrays supported
  • Async Support: Methods can be async (Task, Task<T>) for non-blocking invocation

โœ… Status & Maturity

  • RPC Framework: Core functionality stable, production-tested
  • .NET Target: .NET 8.0+ (primary)
  • Thread Safety: Service methods should be thread-safe if called concurrently
  • Performance: JSON serialization overhead minimal for typical RPC payload sizes
  • Protocol Variants: JSON-RPC 2.0 compatible; extending for additional protocols supported

๐Ÿ“ฆ Dependencies

  • Sphere10 Framework: Core framework
  • Newtonsoft.Json: JSON serialization (handles custom converters for hex, enums)
  • System.Reflection: Service discovery and method invocation
  • System.Net: Networking utilities (protocol-specific implementations)

โš–๏ธ License

Distributed under the MIT NON-AI License.

See the LICENSE file for full details. More information: Sphere10 NON-AI-MIT License

๐Ÿ‘ค Author

Herman Schoenfeld - Software Engineer

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 (1)

Showing the top 1 NuGet packages that depend on Sphere10.Framework.Communications:

Package Downloads
Sphere10.Framework.Application

Application framework and lifecycle management for Sphere10 Framework-based apps. Provides dependency injection integration, settings persistence, command-line argument parsing, product/version metadata, and builder-based startup/shutdown hooks.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.0 194 11/24/2026
3.2.0-ci.186.45519021075.1 0 11/25/2026
3.2.0-ci.185.45437957423.1 54 11/24/2026
3.2.0-ci.184.45433825651.1 52 11/24/2026
3.2.0-ci.179.45429051159.1 55 11/24/2026
3.2.0-ci.176.45423889482.1 51 11/24/2026
3.2.0-ci.175.45417619940.1 52 11/24/2026
3.2.0-ci.174.45412668816.1 56 11/24/2026
3.2.0-ci.173.45375449609.1 65 11/24/2026
3.2.0-ci.171.45374063975.1 60 11/24/2026
3.2.0-ci.169.45350717665.1 58 11/24/2026
3.2.0-ci.168.45166918016.1 105 11/23/2026
3.2.0-ci.163.43664782937.1 71 11/15/2026
3.2.0-ci.160.43660265392.1 64 11/15/2026
3.2.0-ci.159.43537748063.1 60 11/14/2026
3.2.0-ci.158.43536665157.1 66 11/14/2026
3.2.0-ci.157.43350632870.1 66 11/13/2026
3.2.0-ci.156.43233095581.1 65 11/12/2026
3.1.2 155 9/9/2026
3.0.2 156 1/2/2026
Loading failed