protected object InvokeServiceMethod(ServiceMethod serviceMethod, object[] arguments) { switch (serviceMethod.ResponseType) { case MethodResponseType.None: return(null); case MethodResponseType.Sync: return(serviceMethod.Invoke(arguments)); case MethodResponseType.Async: var task = Task.Run(() => (Task)serviceMethod.Invoke(arguments)); if (task.Wait(InvocationTimeout)) { return(0); } else { HandleError(task.Exception as Exception ?? new InvocationTimeoutException(InvocationTimeout, serviceMethod)); return(null); } case MethodResponseType.AsyncWithResult: return(_InvokeServiceMethodAsyncWithResult .MakeGenericMethod(serviceMethod.ReturnType.GetGenericArguments()) .Invoke(this, new object[] { serviceMethod, arguments })); default: HandleError(new ResponseTypeNotSupportedException(serviceMethod.ResponseType)); return(null); } }
private T InvokeServiceMethodAsyncWithResult <T>(ServiceMethod serviceMethod, object[] arguments) { var taskWithResult = Task.Run(new Func <Task <T> >(() => (Task <T>)serviceMethod.Invoke(arguments))); if (taskWithResult.Wait(InvocationTimeout)) { return(taskWithResult.Result); } else { HandleError(taskWithResult.Exception as Exception ?? new InvocationTimeoutException(InvocationTimeout, serviceMethod)); return(default);