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

publicclassExampleCalculatorService:JsonRpcService{[JsonRpcMethod]privatedoubleadd(doublel,doubler){returnl+r;}}

Register that service before it will ever be used

namespaceExample{classConsoleServer{staticobject[]services=newobject[]{newExampleCalculatorService()};}}

Direct input from the console to the JsonRpc Processor and pass the output back to the console

asyncstaticvoidMain(string[]args){for(stringline=Console.ReadLine();!string.IsNullOrEmpty(line);line=Console.ReadLine()){varresponse=awaitJsonRpcProcessor.Process(line);Console.WriteLine(response.Result);}}

Clone this wiki locally