예제 #1
0
 public static RpcTestCase FromJson(JObject json)
 {
     return(new RpcTestCase
     {
         Name = json["Name"].AsString(),
         Request = RpcRequest.FromJson(json["Request"]),
         Response = RpcResponse.FromJson(json["Response"]),
     });
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }