-
Notifications
You must be signed in to change notification settings - Fork 164
Open
Labels
Description
net9.0, StreamJsonRpc 2.22.11
Interface declaration
public interface TestInterface
{
public Task<int> add(int a, int b);
}
Strongly-typed request with named arguments with JsonMessageFormatter
Pipe pipe = new();
var formatter = new JsonMessageFormatter();
var handler = new LengthHeaderMessageHandler(pipe.Writer, pipe.Reader, formatter);
var jsonRpc = new JsonRpc(handler);
jsonRpc.TraceSource.Listeners.Add(new ConsoleTraceListener());
jsonRpc.TraceSource.Switch.Level = SourceLevels.Verbose;
jsonRpc.StartListening();
JsonRpcProxyOptions JsonRpcProxyOptions = new()
{
ServerRequiresNamedArguments = true
};
TestInterface testInterface = jsonRpc.Attach<TestInterface>(JsonRpcProxyOptions);
await testInterface.add(123, 456);
Partial console output
JsonRpc Verbose: 8 : Sent: {
"jsonrpc": "2.0",
"id": 2,
"method": "add",
"params": {
"a": 123,
"b": 456
}
}
Strongly-typed request with named arguments with SystemTextJsonFormatter
Pipe pipe = new();
var formatter = new SystemTextJsonFormatter();
var handler = new LengthHeaderMessageHandler(pipe.Writer, pipe.Reader, formatter);
var jsonRpc = new JsonRpc(handler);
jsonRpc.TraceSource.Listeners.Add(new ConsoleTraceListener());
jsonRpc.TraceSource.Switch.Level = SourceLevels.Verbose;
jsonRpc.StartListening();
JsonRpcProxyOptions JsonRpcProxyOptions = new()
{
ServerRequiresNamedArguments = true
};
TestInterface testInterface = jsonRpc.Attach<TestInterface>(JsonRpcProxyOptions);
await testInterface.add(123, 456);
Partial console output
JsonRpc Verbose: 8 : Sent: {"jsonrpc":"2.0","id":2,"method":"add","params":{}}