Example #1
0
        protected override object Invoke(MethodInfo targetMethod, object[] args)
        {
            ClientActionHanler handler = ClientActionFactory.GetHandler((MethodInfo)targetMethod);
            var rinfo = handler.GetRequestInfo(args);
            var host  = handler.Host != null ? handler.Host : Host;

            if (host == null)
            {
                throw new Exception("The service host is not defined!");
            }
            var request = rinfo.GetRequest(host);
            var task    = request.Execute();

            if (!handler.Async)
            {
                throw new HttpClientException(request, Host.Uri, $"{rinfo.Method} method is not supported and the return value must be task!");
            }
            else
            {
                IAnyCompletionSource source = CompletionSourceFactory.Create(handler.ReturnType, TimeOut);
                source.Wait <Response>(task, (c, t) =>
                {
                    if (t.Result.Exception != null)
                    {
                        c.Error(t.Result.Exception);
                    }
                    else
                    {
                        c.Success(t.Result.Body);
                    }
                });
                return(source.GetTask());
            }
        }
Example #2
0
        protected async Task <T> OnExecute <T>(MethodBase targetMethod, params object[] args)
        {
            var rinfo   = ClientActionFactory.GetHandler((MethodInfo)targetMethod).GetRequestInfo(args);
            var request = rinfo.GetRequest(Host);
            var respnse = await request.Execute();

            if (respnse.Exception != null)
            {
                throw respnse.Exception;
            }
            return((T)respnse.Body);
        }