![]() |
VOOZH | about |
dotnet add package OutWit.Communication.Client --version 2.3.3
NuGet\Install-Package OutWit.Communication.Client -Version 2.3.3
<PackageReference Include="OutWit.Communication.Client" Version="2.3.3" />
<PackageVersion Include="OutWit.Communication.Client" Version="2.3.3" />Directory.Packages.props
<PackageReference Include="OutWit.Communication.Client" />Project file
paket add OutWit.Communication.Client --version 2.3.3
#r "nuget: OutWit.Communication.Client, 2.3.3"
#:package OutWit.Communication.Client@2.3.3
#addin nuget:?package=OutWit.Communication.Client&version=2.3.3Install as a Cake Addin
#tool nuget:?package=OutWit.Communication.Client&version=2.3.3Install as a Cake Tool
Base client library for the WitRPC framework, providing functionality to connect to WitRPC servers and create dynamic proxies for calling remote services over various transports.
OutWit.Communication.Client is the core client-side library in the WitRPC ecosystem. It enables your application to act as a WitRPC client that can connect to remote services hosted by a WitRPC server. This package provides the fundamental client logic, including managing the connection, sending requests, receiving responses, and generating proxy objects that implement your service interfaces on the client side. Using these proxies, you can call remote methods and handle server events as if they were happening locally.
Key capabilities of this client library include:
Dynamic Service Proxies: The client produces a proxy for your service interface (e.g. IMyService) via client.GetService<IMyService>(). This proxy forwards your method calls to the server and raises server-sent events on the client, supporting a natural, object-oriented usage of remote services (no need to manually serialize calls).
Multiple Service Interfaces: When the server hosts multiple service interfaces (using composite services), a single client connection can access all of them. Just call client.GetService<T>() with different interface types to get proxies for each service.
Transport Agnostic: The client library works with any supported transport (Named Pipes, TCP, WebSocket, Memory-Mapped Files, REST, etc.). The actual transport is provided by a transport-specific package, but the client API remains the same. You simply configure the desired transport during setup (for example, using .WithTcp(...), .WithWebSocket(...), etc.) and the library handles the details.
Serialization & Encryption: The client supports all WitRPC serialization options (JSON by default, or MessagePack/others) and can enable encryption and authentication to match the server's configuration. These are toggled via builder options like .WithJson(), .WithMessagePack(), .WithEncryption(), and .WithAccessToken("token") for providing credentials.
Error Handling & Timeouts: You can specify timeouts for connection and calls. The framework will return error statuses or throw exceptions if calls fail or time out, making it easier to handle network issues. The ConnectAsync method allows you to gracefully attempt connections within a specified timeframe.
Auto-Reconnection: The client supports automatic reconnection with configurable retry strategies using WithAutoReconnect().
Retry Policies: Failed calls can be automatically retried using configurable retry policies with WithRetryPolicy().
Under the hood, OutWit.Communication.Client works with the core OutWit.Communication components to format requests and decode responses. In most cases, you will use this package by including a transport-specific client package which depends on it, rather than using OutWit.Communication.Client alone.
Install-Package OutWit.Communication.Client
Note: In practice, you will typically install a specific client transport package (such as OutWit.Communication.Client.Tcp, OutWit.Communication.Client.WebSocket, etc.) which will automatically include this base library. Choose a transport package that matches the server's transport. For example, if the server uses TCP, install OutWit.Communication.Client.Tcp in the client application.
To use the WitRPC client, first ensure you have a matching server running (using the corresponding OutWit.Communication.Server.* package). In your client code, you build and connect a client as follows:
using OutWit.Communication.Client;
using OutWit.Communication.Client.Pipes; // example transport: Named Pipes
using OutWit.Communication.Serializers;
using OutWit.Communication.Client.Encryption;
var client = WitClientBuilder.Build(options =>
{
// Configure the transport (Named Pipe in this example):
options.WithNamedPipe("MyAppPipe");
// Use JSON serialization and enable encryption to match the server:
options.WithJson();
options.WithEncryption();
// If the server requires an access token for authorization:
// options.WithAccessToken("SecureTokenValue");
});
bool connected = await client.ConnectAsync(TimeSpan.FromSeconds(5));
if (!connected)
{
Console.Error.WriteLine("Unable to connect to the RPC server.");
return;
}
// Obtain a proxy to the remote service interface
IMyService service = client.GetService<IMyService>();
// Now you can call methods on the service and subscribe to events as if it were local:
service.SomeMethod("Hello");
service.SomeEvent += data => Console.WriteLine($"Event from server: {data}");
In this example, we built a client to connect via a named pipe called "MyAppPipe". The server must also be configured to listen on "MyAppPipe" (using OutWit.Communication.Server.Pipes) for the connection to succeed. We enabled JSON serialization and encryption in the client to align with the server's settings. We also demonstrate calling a method SomeMethod on the service and subscribing to an event SomeEvent. The call to SomeMethod will be sent to the server's implementation, and any SomeEvent raised on the server will invoke our console WriteLine on the client side.
Transport Selection: The above used Named Pipes for illustration, but you would use the transport relevant to your scenario. For example, to connect via TCP: use options.WithTcp("server-address", port), or for WebSocket: options.WithWebSocket("ws://server:port/path"). Just ensure the server is using the corresponding server transport with matching parameters (pipe name, port number, URL path, etc.).
Dynamic Proxies: After connecting, calling client.GetService<T>() returns an object of interface T that acts as a live proxy to the server. You do not need to write any networking code: simply call methods on this proxy as you would on a local object. The WitRPC client takes care of packaging the call, sending it to the server, and unwrapping the response. If the server triggers an event, the proxy raises that event on the client side.
Tip: This base client library works behind the scenes. In a typical application, you will primarily interact with the builder (to configure transports/security) and the proxy object. The heavy lifting of managing sockets, threads, or pipe streams is handled internally by this library and the transport plugins.
When the server hosts multiple service interfaces using composite services, a single client can access all of them:
// Server hosts IUserService, IOrderService, and INotificationService
var client = WitClientBuilder.Build(options =>
{
options.WithTcp("localhost", 5000);
options.WithJson();
options.WithEncryption();
});
await client.ConnectAsync(TimeSpan.FromSeconds(5));
// Get proxies for different service interfaces
var userService = client.GetService<IUserService>();
var orderService = client.GetService<IOrderService>();
var notificationService = client.GetService<INotificationService>();
// Use each service
var user = userService.GetUser(userId);
var orders = orderService.GetOrdersForUser(userId);
notificationService.SendNotification(user.Email, "Your orders are ready!");
The above used Named Pipes for illustration, but you would use the transport relevant to your scenario:
// TCP
options.WithTcp("server-address", port);
// WebSocket
options.WithWebSocket("ws://server:port/path");
// Named Pipes
options.WithNamedPipe("PipeName");
Just ensure the server is using the corresponding server transport with matching parameters (pipe name, port number, URL path, etc.).
Enable automatic reconnection for resilient connections:
var client = WitClientBuilder.Build(options =>
{
options.WithTcp("localhost", 5000);
options.WithJson();
options.WithAutoReconnect(reconnect =>
{
reconnect.MaxAttempts = 5;
reconnect.InitialDelay = TimeSpan.FromSeconds(1);
reconnect.MaxDelay = TimeSpan.FromSeconds(30);
});
});
See the WitRPC documentation for advanced client usage, including using the source generator (OutWit.Common.Proxy.Generator) for compile-time proxy generation and debugging tips.
Licensed under the Apache License, Version 2.0. See LICENSE.
If you use OutWit.Communication.Client in a product, a mention is appreciated (but not required), for example: "Powered by WitRPC (https://witrpc.io/)".
"WitRPC" and the WitRPC logo are used to identify the official project by Dmitry Ratner.
You may:
You may not:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on OutWit.Communication.Client:
| Package | Downloads |
|---|---|
|
OutWit.Communication.Client.WebSocket
WebSocket transport client for WitRPC, enabling real-time, full-duplex communication over WebSocket connections (great for internet or browser-based clients). |
|
|
OutWit.Communication.Client.Pipes
Named Pipes transport client for WitRPC, allowing efficient inter-process communication via named pipes on the local machine (with support for multiple clients). |
|
|
OutWit.Communication.Client.MMF
Memory-mapped file transport client for WitRPC, enabling high-speed inter-process communication via a shared memory region (for on-machine RPC calls). |
|
|
OutWit.Communication.Client.Tcp
TCP transport client for WitRPC, enabling network communication over TCP sockets (with optional TLS support) to connect to WitRPC servers. |
|
|
OutWit.InterProcess.Host
Provides host-side functionality to launch external processes and connect to them via WitRPC, allowing your application to use out-of-process services as if they were local (handles process startup and client proxy generation). |
This package is not used by any popular GitHub repositories.