private void ExecuteOnJsonServiceClient(JsonServiceClient client, object dto) { var parameterType = dto.GetType(); var returnType = parameterType.GetInterfaces().FirstOrDefault(); if (returnType != null) { string invokeMethod = this.lsRequestMethod.SelectedItem.ToString(); if (returnType == typeof(IReturnVoid)) { var method = client.GetType().GetMethods().FirstOrDefault(m => m.Name == invokeMethod && !m.IsGenericMethod && !m.IsStatic); if (method != null) { method.Invoke(client, new object[] { dto }); this.tbResponse.Json = "Request sent successfully."; } } else if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(IReturn <>)) { Type returnDtoType = returnType.GetGenericArguments()[0]; var method = client.GetType().GetMethods().FirstOrDefault(m => m.Name == invokeMethod && m.IsGenericMethod && !m.IsStatic); if (method != null) { var response = method.MakeGenericMethod(new Type[] { returnDtoType }).Invoke(client, new object[] { dto }); if (response != null) { JsConfig <DateTime> .SerializeFn = time => time.ToString(); JsConfig <DateTime?> .SerializeFn = time => time == null ? string.Empty : time.ToString(); this.tbResponse.Json = JsonSerializer.SerializeToString(response); } } } } }