Example #1
0
        /// <summary>
        /// 调用后台服务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="transactionCode">交易号</param>
        /// <param name="transactionParameter">交易参数</param>
        /// <param name="fakeMode">是否使用虚拟的值填充返回值,该模式下,从本地JSON文件中读取数据,方便调试</param>
        /// <returns></returns>
        private JavaServiceResult <T> CallService <T>(string sysName, string transactionCode, object transactionParameter, bool fakeMode)
        {
            var ulr            = this.ServiceInfo.Config.GetValue(sysName).ToObject <Dictionary <string, string> >()["ServiceUrl"];
            var serviceInvoker = new JavaServiceInvoker(new Uri(ulr), this.IsLoginService, false);

            serviceInvoker.Error           += serviceInvoker_Error;
            serviceInvoker.ProgressChanged += serviceInvoker_ProgressChanged;
            return(serviceInvoker.Invoke <T>(transactionCode, transactionParameter));
        }
Example #2
0
        private void CallServiceAsync <T>(string sysName, string transactionCode, object transactionParameter, bool fakeMode, Action <T> onSuccess, Action <string> onError)
        {
            var backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork += (sender, e) =>
            {
                var ulr            = this.ServiceInfo.Config.GetValue(sysName).ToObject <Dictionary <string, string> >()["ServiceUrl"];
                var serviceInvoker = new JavaServiceInvoker(new Uri(ulr), this.IsLoginService, true);
                e.Result = serviceInvoker.Invoke <T>(transactionCode, transactionParameter);
            };

            backgroundWorker.RunWorkerCompleted += (sender, e) =>
            {
                var sr = (e.Result as JavaServiceResult <T>).ToServiceResult();
                if (sr.Success)
                {
                    if (onSuccess != null)
                    {
                        onSuccess(sr.Value);
                    }
                }
                else
                {
                    if (onError != null)
                    {
                        onError(sr.Message);                   //外界传递错误处理回调,使用错误回调处理
                    }
                    else
                    {
                        ServiceFactory.NotifyError(null, (e.Result as JavaServiceResult <T>).ErrorInfo);
                    }
                }
            };

            backgroundWorker.RunWorkerAsync();
        }