public static RpcTestCase FromJson(JObject json) { return(new RpcTestCase { Name = json["Name"].AsString(), Request = RpcRequest.FromJson(json["Request"]), Response = RpcResponse.FromJson(json["Response"]), }); }
static RpcResponse AsRpcResponse(string content) { var response = RpcResponse.FromJson(JObject.Parse(content)); response.RawResponse = content; if (response.Error != null) { throw new RpcException(response.Error.Code, response.Error.Message); } return(response); }
private static async Task <RpcResponse> MakeRequestAsync(string methodName, params object[] args) { var response = await client.PostAsync("", new StringContent(MethodCallContext.ToJson(MyVersion, methodName, args))); var result = RpcResponse.FromJson(await ReadContent(response)); if (result.JsonRpcVersion != MyVersion) { throw new Exception($"Incompatible RPC versions result {result.JsonRpcVersion} vs current {MyVersion}"); } if (result.Error != null) { throw new Exception(result.Error?.Message); } return(result); }
public async Task <RpcResponse> SendAsync(RpcRequest request) { var requestJson = request.ToJson().ToString(); var result = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(requestJson, Encoding.UTF8)); var content = await result.Content.ReadAsStringAsync(); var response = RpcResponse.FromJson(JObject.Parse(content)); response.RawResponse = content; if (response.Error != null) { throw new RpcException(response.Error.Code, response.Error.Message); } return(response); }
public async Task <RpcResponse> SendAsync(RpcRequest request) { if (disposedValue) { throw new ObjectDisposedException(nameof(RpcClient)); } var requestJson = request.ToJson().ToString(); using var result = await httpClient.PostAsync(baseAddress, new StringContent (requestJson, Encoding.UTF8)).ConfigureAwait(false); var content = await result.Content.ReadAsStringAsync(); var response = RpcResponse.FromJson(JObject.Parse(content)); response.RawResponse = content; if (response.Error != null) { throw new RpcException(response.Error.Code, response.Error.Message); } return(response); }