public Client(ClientSettings settings, ClientVariables variables, RestartCallback restartCb, WebApiOptions?webOptions = null, CancellationToken cancel = default) : base(cancel) { settings.Validate(); // 設定とデータをコピーする this.Settings = settings._CloneDeep(); this.Variables = variables._CloneDeep(); this.StartupParams = new OneLineParams(variables.CurrentInstanceArguments._NonNull()); this.Report_ForceGc = this.StartupParams._HasKey(Consts.DaemonArgKeys.ForceGc); // Web オプションを設定する if (webOptions == null) { webOptions = new WebApiOptions(); } if (settings.ServerCertSha._IsEmpty()) { webOptions.Settings.SslAcceptAnyCerts = true; } else { webOptions.Settings.SslAcceptCertSHAHashList.Clear(); webOptions.Settings.SslAcceptCertSHAHashList.Add(settings.ServerCertSha); webOptions.Settings.SslAcceptAnyCerts = false; } // Proxy の利用設定 webOptions.Settings.UseProxy = settings.UseProxy; // RPC Client を作成する this.RpcClient = new JsonRpcHttpClient(this.Settings.ServerUrl._NullCheck(), webOptions); // RPC インターフェイスを作成する this.Rpc = this.RpcClient.GenerateRpcInterface <IRpc>(); this.RestartCb = restartCb; // メインループを開始する this.StartMainLoop(MainLoopAsync); }
static async Task MainAsync() { Console.WriteLine("Call `Server.listMethods` (raw response):"); using (var client = new JsonRpcHttpClient("http://localhost:56956/api")) { var response = await client.CallAsync("Server.listMethods", null); Console.WriteLine($"\t=> id: {response.Id}"); Console.WriteLine($"\t=> result: {response.Result}"); Console.WriteLine($"\t=> error: {response.Error}"); } Console.WriteLine(); Console.WriteLine("Call `Server.listMethods` (typed response):"); using (var client = new JsonRpcHttpClient("http://localhost:56956/api")) { var response = await client.CallAsync <string[]>("Server.listMethods", null); Console.WriteLine($"\t=> {string.Join(", ", response)}"); } Console.WriteLine(); Console.WriteLine("Call `Storage.upload` (typed response, stream request):"); using (var client = new JsonRpcHttpClient("http://localhost:56956/api")) { using (var stream = new MemoryStream()) { stream.Write(new byte[] { 0x01, 0x02, 0x03, 0x04 }, 0, 4); stream.Seek(0, SeekOrigin.Begin); var response = await client.CallAsync <string[]>("Storage.upload", new { file = new StreamBlob("test-file.bin", stream) }); Console.WriteLine($"\t=> {string.Join(", ", response)}"); } } Console.WriteLine(); }
public static void jsonrpc_client_server_both_test() { //jsonrpc_server_invoke_test().Wait();return; // start server HttpServerOptions http_cfg = new HttpServerOptions() { DebugKestrelToConsole = false, }; JsonRpcServerConfig rpc_cfg = new JsonRpcServerConfig() { }; using (RpcServerApiTest h = new RpcServerApiTest()) using (var s = JsonRpcHttpServerBuilder.StartServer(http_cfg, rpc_cfg, h)) { Ref <bool> client_stop_flag = new Ref <bool>(); // start client ThreadObj client_thread = ThreadObj.Start(param => { //Kernel.SleepThread(-1); //using () { //c.AddHeader("X-1", "Hello"); rpctmp1 t = new rpctmp1(); t.a = new rpc_t() { Int1 = 2, Str1 = "Neko", }; //JsonRpcResponse<object> ret = c.CallOne<object>("Test1", t).Result; //JsonRpcResponse<object> ret = c.CallOne<object>("Test2", t).Result; Benchmark b = new Benchmark("rpccall"); JsonRpcHttpClient <rpc_server_api_interface_test> c = new JsonRpcHttpClient <rpc_server_api_interface_test>("http://127.0.0.1:88/rpc"); var threads = ThreadObj.StartMany(256, par => { while (client_stop_flag.Value == false) { //c.Call.Divide(8, 2).Wait(); TMP1 a = new TMP1() { a = 4, b = 2 }; c.MT_Call <object>("Divide", a, true)._GetResult(); //c.ST_CallOne<object>("Divide", a, true).Wait(); b.IncrementMe++; } } ); foreach (var thread in threads) { thread.WaitForEnd(); } //c.Call.Divide(8, 2).Result.Print(); //c.Call.Divide(8, 2).Result.Print(); //c.Call.Test3(1, 2, 3).Result.Print(); //c.Call.Test5(1, "2").Result.ObjectToJson().Print(); //var fnlist = c.Call.Test6().Result; ////foreach (var fn in fnlist) fn.Print(); //c.Call.Test7(fnlist).Result.Print(); //Con.WriteLine(ret.ObjectToJson()); } }, null); Con.ReadLine("Enter to quit>"); client_stop_flag.Set(true); client_thread.WaitForEnd(); } }
public JsonRpc20Tests() { _Client = new JsonRpcHttpClient(new Uri(ServiceAddress)); }
public AriaManager(string secret, string rpcUrl = "http://localhost:6800/jsonrpc") { this.secret = secret; this.rpcClient = new JsonRpcHttpClient(rpcUrl); }
public AriaManager(string rpcUrl = "http://localhost:6800/jsonrpc") { RpcClient = new JsonRpcHttpClient(new Uri(rpcUrl)); }