Skip to content

Getting Started (Console)

Austin Harris edited this page Sep 22, 2020 · 4 revisions

Using json-rpc.net within a console application;

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

  async static void Main(string[] args)
        {
            for (string line = Console.ReadLine(); !string.IsNullOrEmpty(line); line = Console.ReadLine())
            {
                var response = await JsonRpcProcessor.Process(line);
                Console.WriteLine(response.Result);
            }
        }
Clone this wiki locally