*Create a console application
*Install Json-Rpc.Net Core using NuGet
*Create a JsonRpcService
public class ExampleCalculatorService : JsonRpcService
{
[JsonRpcMethod]
private double add(double l, double r)
{
return l+r;
}
}
*Register that service before it will ever be used
namespace Example
{
class ConsoleServer
{
static object[] services = new object[] {
new ExampleCalculatorService()
};
}
}
*Direct input from the console to the JsonRpc Processor and pass the output back to the console
static void Main(string[] args)
{
var rpcResultHandler = new AsyncCallback(_ => Console.WriteLine(((JsonRpcStateAsync)_).Result));
for (string line = Console.ReadLine(); !string.IsNullOrEmpty(line); line = Console.ReadLine())
{
var async = new JsonRpcStateAsync(rpcResultHandler, null);
async.JsonRpc = line;
JsonRpcProcessor.Process(async);
}
}