Website Logo Light Website Logo Dark OUTWIT

WitRPC


Modernizing Client-Server Communication

WitRPC is a powerful and versatile .NET library designed to simplify client-server and inter-process communication through an intuitive, interface-driven architecture. As a modern successor to WCF, WitRPC provides a unified programming model to define communication contracts using standard C# interfaces, abstracting away the complexities of serialization, transport, and security. It supports multiple transport mechanisms like WebSocket, TCP, Named Pipes, and Memory-Mapped Files (MMF), catering to diverse application scenarios—from inter-process communication to distributed systems.

Key Features of WitRPC

Interface-Driven, Duplex Communication

WitRPC utilizes standard .NET interfaces to define service contracts, enabling seamless duplex (two-way) communication. Events, callbacks, and delegates (e.g., PropertyChangedEventHandler) are first-class citizens, making it ideal for real-time updates, data synchronization, and collaborative systems.

Transparent Proxy Mechanism

WitRPC automatically creates client-side proxies that mirror server interfaces, allowing developers to interact with remote services as if they were local objects. All communication details are transparently handled by WitRPC.

Transport Versatility

WitRPC supports a wide range of transport mechanisms:

  • Memory-Mapped Files (MMF): Ultra-fast IPC on a single machine.

  • Named Pipes: Secure, high-speed local IPC.

  • TCP: Robust network communication.

  • WebSocket: Real-time bidirectional communication with web clients.

Serialization Flexibility

WitRPC offers multiple serialization formats to balance performance, payload size, and readability:

  • JSON: Default, human-readable, widely compatible.

  • MessagePack: Compact binary format.

  • MemoryPack: High-performance, zero-copy binary serializer.

  • ProtoBuf: Efficient, schema-driven binary format.

Extensible Security

Built-in RSA/AES encryption and token-based authorization ensure secure communication. Custom encryption and validation logic can be implemented for integration with enterprise identity systems.

Example Setup with WitRPC

Here’s a simple example to demonstrate WitRPC using a basic calculator service:

Define the Shared Interface

Calculator.Shared/ICalculatorService.cs
namespace Calculator.Shared;
public interface ICalculatorService
{
Task<int> Add(int a, int b);
Task<int> Subtract(int a, int b);
}

Implement the Service

Calculator.Server/CalculatorService.cs
using Calculator.Shared;
namespace Calculator.Server;
public class CalculatorService : ICalculatorService
{
public Task<int> Add(int a, int b)
{
Console.WriteLine($"Add: {a} + {b}");
return Task.FromResult(a + b);
}
public Task<int> Subtract(int a, int b)
{
Console.WriteLine($"Subtract: {a} - {b}");
return Task.FromResult(a - b);
}
}

Configure and Launch WitRPC Server

Calculator.Server/Program.cs
using Calculator.Server;
using OutWit.Communication.Server;
var service = new CalculatorService();
var server = WitServerBuilder.Build(options =>
{
options.WithService(service)
.WithNamedPipe("CalculatorPipe")
.WithJson()
.WithEncryption()
.WithTimeout(TimeSpan.FromSeconds(5));
});
server.StartWaitingForConnection();
Console.ReadKey();
server.StopWaitingForConnection();

Configure and Connect the WitRPC Client

Calculator.Client/Program.cs
using Calculator.Shared;
using OutWit.Communication.Client;
var client = WitClientBuilder.Build(options =>
{
options.WithNamedPipe("CalculatorPipe")
.WithJson()
.WithEncryption()
.WithTimeout(TimeSpan.FromSeconds(5));
});
await client.ConnectAsync(TimeSpan.FromSeconds(10), CancellationToken.None);
var calculator = client.GetService<ICalculatorService>();
int sum = await calculator.Add(10, 5);
Console.WriteLine($"Result: {sum}");
await client.DisconnectAsync();

WitRPC Advantages

  • Ease of Use: Minimal boilerplate code, intuitive setup.
  • Event-Driven Model: Ideal for reactive, real-time apps.
  • Performance: Optimized transport mechanisms for diverse scenarios.
  • Flexibility: Extensive customization of transport, serialization, and security.

WitRPC empowers .NET developers with a robust yet simple framework that addresses modern communication needs, significantly enhancing productivity, maintainability, and system reliability.

Learn more

Explore the complete source code and examples for WitRPC: