*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);
            }
        }

Last edited Sep 19, 2012 at 5:30 AM by AustinHarris, version 1

Comments

Raptor22 May 6, 2014 at 4:59 AM 
Is there a way to give this service an endpoint so that I can call it from another application (indeed, from another machine)?