.NET Client
Use the IonClient to make typed RPC calls from .NET applications — unary HTTP calls and WebSocket streaming.
Setup
using ion.runtime.client; var client = new IonClient("https://api.example.com"); // Create a typed service proxy var userService = client.ForService<IUserService>(spaceId: 1);
ForService<T> creates a typed proxy that passes base arguments to every call.
Unary Calls
// Simple request-response User user = await userService.GetUser(userId: 42); Console.WriteLine(user.name); // fully typed // Fire-and-forget (void method) await userService.SendNotification(userId: 42, text: "Hello");
Under the hood, the proxy:
- Serializes
[spaceId, userId]to CBOR - POSTs to
/ion/UserService/GetUser.unary - Deserializes the CBOR response body into
User
Streaming Calls
// Server streaming via WebSocket await foreach (var user in userService.WatchUpdates()) { Console.WriteLine($"Updated: {user.name}"); } // Bidirectional streaming var channel = Channel.CreateUnbounded<float>(); await foreach (var result in streamService.Floats(channel.Reader.ReadAllAsync())) { Console.WriteLine(result); }
Error Handling
RPC errors are thrown as IonProtocolError:
try { var user = await userService.GetUser(999); } catch (IonProtocolError ex) { Console.WriteLine($"Error {ex.Code}: {ex.Message}"); }
Authentication
var client = new IonClient("https://api.example.com", options => { options.Ticket = "eyJhbGciOiJIUzI1NiIs..."; });
The ticket is sent via the subprotocol header for WebSocket connections and via a custom header for HTTP requests.
Deadlines
Methods annotated with @deadline(ms) in the schema have automatic request timeouts:
// In the schema: @deadline(5000) service SearchService() { Search(query: string): SearchResult; } // C# client — auto-cancels after 5 seconds var result = await searchService.Search("hello");