public string ProcessHttpRequest(RequestArgs requestArgs) { MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "接受Http请求:" + requestArgs.ToString()); //获取的池子索引 int? index = null; ClientLink clientlink = null; ClientLinkPool pool = fromPoolGetClientLink(requestArgs.plugin, out clientlink, out index); ServiceResponseData retData = new ServiceResponseData(); try { //绑定LoginRight Action <ClientRequestData> _requestAction = ((ClientRequestData request) => { request.LoginRight = requestArgs.sysright; request.SetJsonData(requestArgs.jsondata); }); retData = clientlink.Request(requestArgs.controller, requestArgs.method, _requestAction); } catch (Exception ex) { throw ex; } finally { if (index != null) { pool.ReturnPool(requestArgs.plugin, (int)index); } } return(retData.GetJsonData()); }
/// <summary> /// 客户端执行订阅服务 /// </summary> /// <param name="_clientLink"></param> public static void ProcessPublishService(string publishServiceName, ClientLink _clientLink) { switch (publishServiceName) { case "DistributedCache": //分布式缓存服务 List <CacheIdentify> ciList = DistributedCacheClient.GetCacheIdentifyList(); List <CacheObject> coList = _clientLink.GetDistributedCacheData(ciList); if (coList.Count > 0) { DistributedCacheClient.SetCacheObjectList(coList); } break; case "RemotePlugin": //远程插件服务 LocalPlugin localPlugin = RemotePluginClient.GetLocalPlugin(); if (localPlugin.PluginDic.Count > 0) { _clientLink.RegisterRemotePlugin(WcfGlobal.Identify, localPlugin.PluginDic.Keys.ToArray()); } break; case "UpgradeClient": //客户端升级 ClientUpgradeManager.DownLoadUpgrade(); break; case "UpgradeServer": //中间件升级 break; case "MongodbSync": //同步Mongodb数据 break; case "MiddlewareMonitor": //中间件集群监控服务 break; case "MiddlewareCmd": //中间件命令服务 break; default: PublishServiceObject pso = psoList.Find(x => x.publishServiceName == publishServiceName); MiddlewareLogHelper.WriterLog(LogType.MidLog, true, System.Drawing.Color.Blue, string.Format("正在执行服务{0}/{1}/{2}/{3}", pso.pluginname, pso.controller, pso.method, pso.argument)); ServiceResponseData retjson = InvokeWcfService( pso.pluginname , pso.controller , pso.method , (ClientRequestData request) => { request.SetJsonData(pso.argument); }); string txtResult = retjson.GetJsonData(); MiddlewareLogHelper.WriterLog(LogType.MidLog, true, System.Drawing.Color.Blue, string.Format("服务执行完成,返回结果:{0}", txtResult)); break; } ShowHostMsg(Color.Blue, DateTime.Now, "执行“" + publishServiceName + "”订阅服务成功!"); }
public string TestRemoteService(string identify, string plugin, string controller, string method, string para) { Action <ClientRequestData> requestAction = ((ClientRequestData request) => { request.Iscompressjson = false; request.Isencryptionjson = false; request.Serializetype = SerializeType.Newtonsoft; request.LoginRight = new SysLoginRight(1); request.SetJsonData(para); }); ClientLink link = new ClientLink(null, plugin, null, null, null, identify); link.CreateConnection(); ServiceResponseData response = link.Request(controller, method, requestAction); return(response.GetJsonData()); }
static void CallService() { ClientLink clientlink = new ClientLink("Books.Service"); clientlink.CreateConnection(); Action <ClientRequestData> _requestAction = ((ClientRequestData request) => { request.LoginRight = new EFWCoreLib.CoreFrame.Business.SysLoginRight(1); }); ServiceResponseData retData = clientlink.Request("bookWcfController", "GetBooks", _requestAction); string data = retData.GetJsonData(); clientlink.UnConnection(); Console.WriteLine(data); }
public LoginResponse UserLogin([FromBody] LoginRequest loginreq) { LoginResponse loginres = new LoginResponse(); try { Action <ClientRequestData> requestAction = ((ClientRequestData request) => { request.Iscompressjson = false; request.Isencryptionjson = false; request.Serializetype = SerializeType.Newtonsoft; request.AddData(loginreq.usercode); request.AddData(loginreq.password); }); ServiceResponseData response = InvokeWcfService(loginreq.wcfpluginname, loginreq.wcfcontroller, loginreq.wcfmethod, requestAction); loginres.otherdata = JsonConvert.DeserializeObject(response.GetJsonData()); AuthResult authres = SsoHelper.ValidateUserId(loginreq.usercode); if (authres.ErrorMsg == string.Empty) { loginres.flag = true; loginres.msg = string.Empty; loginres.token = authres.token; loginres.usercode = authres.User.UserId; loginres.username = authres.User.UserName; loginres.deptname = authres.User.DeptName; loginres.workname = authres.User.WorkName; } else { throw new Exception(authres.ErrorMsg); } } catch (Exception e) { loginres.flag = false; loginres.msg = "登录失败:" + e.Message; } return(loginres); }
private void btnRequest_Click(object sender, EventArgs e) { try { btnRequest.Enabled = false; ServiceResponseData retjson = ClientLinkManage.CreateConnection(cbplugin.Text).Request(string.Format("{0}", cbcontroller.Text), cbmothed.Text, (ClientRequestData request) => { request.SetJsonData(txtparams.Text.Trim()); }); txtResult.Text = retjson.GetJsonData(); } catch (Exception err) { MessageBox.Show(err.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { btnRequest.Enabled = true; } }
public string TestServices(string plugin, string controller, string method, string para) { try { Action <ClientRequestData> requestAction = ((ClientRequestData request) => { request.Iscompressjson = false; request.Isencryptionjson = false; request.Serializetype = SerializeType.Newtonsoft; //request.LoginRight = new CoreFrame.Business.SysLoginRight(1); request.SetJsonData(para); }); ServiceResponseData response = InvokeWcfService(plugin, controller, method, requestAction); return(response.GetJsonData()); } catch (Exception e) { throw e; } }
//Accept: application/json //Content-Type: application/json ///efwplusApi/coresys/service/post?token=111111 ///{"wcfpluginname":"Books.Service","wcfcontroller":"bookWcfController","wcfmethod":"GetBooks","jsondata":"[]"} public Object Post([FromBody] ServiceParam data) { try { if (data == null) { return(null); } Action <ClientRequestData> requestAction = ((ClientRequestData request) => { request.Iscompressjson = false; request.Isencryptionjson = false; request.Serializetype = SerializeType.Newtonsoft; request.SetJsonData(data.jsondata); }); ServiceResponseData response = InvokeWcfService(data.wcfpluginname, data.wcfcontroller, data.wcfmethod, requestAction); return(JsonConvert.DeserializeObject(response.GetJsonData())); } catch (Exception err) { return("服务执行错误###" + err.Message); } }
public static string ProcessRequest(string clientId, string plugin, string controller, string method, string jsondata, HeaderParameter para) { string retJson = null; try { if (plugin == null || controller == null) { throw new Exception("插件名称或控制器名称不能为空!"); } if (ClientManage.ClientDic.ContainsKey(clientId) == false) { throw new Exception("客户端不存在,正在创建新的连接!"); } if (ClientManage.IsToken == true)//非调试模式下才验证 { //验证身份,创建连接的时候验证,请求不验证 IsAuth(plugin, controller, method, para.token); } //显示调试信息 if (WcfGlobal.IsDebug == true) { ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + clientId + "]正在执行:" + controller + "." + method + "(" + jsondata + ")"); } begintime(); #region 执行插件控制器的核心算法 object[] paramValue = null;//jsondata? ServiceResponseData retObj = null; LocalPlugin localPlugin = RemotePluginManage.GetLocalPlugin(); if (string.IsNullOrEmpty(para.replyidentify) || localPlugin.ServerIdentify == para.replyidentify) { if (localPlugin.PluginDic.ContainsKey(plugin) == true) { //先解密再解压 string _jsondata = jsondata; //解密参数 if (para.isencryptionjson) { DESEncryptor des = new DESEncryptor(); des.InputString = _jsondata; des.DesDecrypt(); _jsondata = des.OutString; } //解压参数 if (para.iscompressjson) { _jsondata = ZipComporessor.Decompress(_jsondata); } ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype); requestData.SetJsonData(_jsondata); requestData.LoginRight = para.LoginRight; EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = localPlugin.PluginDic[plugin]; retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData); if (retObj != null) { retJson = retObj.GetJsonData(); } else { retObj = new ServiceResponseData(); retObj.Iscompressjson = para.iscompressjson; retObj.Isencryptionjson = para.isencryptionjson; retObj.Serializetype = para.serializetype; retJson = retObj.GetJsonData(); } retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}"; //先压缩再加密 //压缩结果 if (para.iscompressjson) { retJson = ZipComporessor.Compress(retJson); } //加密结果 if (para.isencryptionjson) { DESEncryptor des = new DESEncryptor(); des.InputString = retJson; des.DesEncrypt(); retJson = des.OutString; } } else { throw new Exception("本地插件找不到指定的插件"); } } else//本地插件找不到,就执行远程插件 { if (RemotePluginManage.GetRemotePlugin().FindIndex(x => x.ServerIdentify == para.replyidentify) > -1) { RemotePlugin rp = RemotePluginManage.GetRemotePlugin().Find(x => x.ServerIdentify == para.replyidentify); string[] ps = rp.plugin; if (ps.ToList().FindIndex(x => x == plugin) > -1) { retJson = rp.callback.ReplyProcessRequest(para, plugin, controller, method, jsondata); } else { throw new Exception("远程插件找不到指定的插件"); } } else { throw new Exception("远程插件找不到指定的回调中间件"); } } #endregion double outtime = endtime(); //记录超时的方法 if (ClientManage.IsOverTime == true) { if (outtime > Convert.ToDouble(ClientManage.OverTime * 1000)) { WriterOverTimeLog(outtime, controller + "." + method + "(" + jsondata + ")"); } } //显示调试信息 if (WcfGlobal.IsDebug == true) { ShowHostMsg(Color.Green, DateTime.Now, "客户端[" + clientId + "]收到结果(耗时[" + outtime + "]):" + retJson); } //更新客户端信息 ClientManage.UpdateRequestClient(clientId, jsondata == null ? 0 : jsondata.Length, retJson == null ? 0 : retJson.Length); if (retJson == null) { throw new Exception("插件执行未返回有效数据"); } return(retJson); } catch (Exception err) { //记录错误日志 if (err.InnerException == null) { retJson = "{\"flag\":1,\"msg\":" + "\"" + err.Message + "\"" + "}"; if (para.iscompressjson) { retJson = ZipComporessor.Compress(retJson); } ShowHostMsg(Color.Red, DateTime.Now, "客户端[" + clientId + "]执行失败:" + err.Message); return(retJson); } else { retJson = "{\"flag\":1,\"msg\":" + "\"" + err.InnerException.Message + "\"" + "}"; if (para.iscompressjson) { retJson = ZipComporessor.Compress(retJson); } ShowHostMsg(Color.Red, DateTime.Now, "客户端[" + clientId + "]执行失败:" + err.InnerException.Message); return(retJson); } } }
public static string ReplyProcessRequest(string plugin, string controller, string method, string jsondata, HeaderParameter para) { string retJson = null; try { //显示调试信息 if (WcfGlobal.IsDebug == true) { ShowHostMsg(Color.Black, DateTime.Now, "客户端[本地回调]正在执行:" + controller + "." + method + "(" + jsondata + ")"); } begintime(); #region 执行插件控制器的核心算法 object[] paramValue = null;//jsondata? ServiceResponseData retObj = null; LocalPlugin localPlugin = RemotePluginManage.GetLocalPlugin(); if (string.IsNullOrEmpty(para.replyidentify) || localPlugin.ServerIdentify == para.replyidentify) { if (localPlugin.PluginDic.ContainsKey(plugin) == true) { //先解密再解压 string _jsondata = jsondata; //解密参数 if (para.isencryptionjson) { DESEncryptor des = new DESEncryptor(); des.InputString = _jsondata; des.DesDecrypt(); _jsondata = des.OutString; } //解压参数 if (para.iscompressjson) { _jsondata = ZipComporessor.Decompress(_jsondata); } ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype); requestData.SetJsonData(_jsondata); requestData.LoginRight = para.LoginRight; EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = localPlugin.PluginDic[plugin]; retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData); if (retObj != null) { retJson = retObj.GetJsonData(); } else { retObj = new ServiceResponseData(); retObj.Iscompressjson = para.iscompressjson; retObj.Isencryptionjson = para.isencryptionjson; retObj.Serializetype = para.serializetype; retJson = retObj.GetJsonData(); } retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}"; //先压缩再加密 //压缩结果 if (para.iscompressjson) { retJson = ZipComporessor.Compress(retJson); } //加密结果 if (para.isencryptionjson) { DESEncryptor des = new DESEncryptor(); des.InputString = retJson; des.DesEncrypt(); retJson = des.OutString; } } else { throw new Exception("本地插件找不到指定的插件"); } } else//本地插件找不到,就执行远程插件 { if (RemotePluginManage.GetRemotePlugin().FindIndex(x => x.ServerIdentify == para.replyidentify) > -1) { RemotePlugin rp = RemotePluginManage.GetRemotePlugin().Find(x => x.ServerIdentify == para.replyidentify); string[] ps = rp.plugin; if (ps.ToList().FindIndex(x => x == plugin) > -1) { retJson = rp.callback.ReplyProcessRequest(para, plugin, controller, method, jsondata); } else { throw new Exception("远程插件找不到指定的插件"); } } else { throw new Exception("远程插件找不到指定的回调中间件"); } } #endregion //System.Threading.Thread.Sleep(20000);//测试并发问题,此处也没有问题 double outtime = endtime(); //记录超时的方法 if (ClientManage.IsOverTime == true) { if (outtime > Convert.ToDouble(ClientManage.OverTime * 1000)) { WriterOverTimeLog(outtime, controller + "." + method + "(" + jsondata + ")"); } } //显示调试信息 if (WcfGlobal.IsDebug == true) { ShowHostMsg(Color.Green, DateTime.Now, "客户端[本地回调]收到结果(耗时[" + outtime + "]):" + retJson); } if (retJson == null) { throw new Exception("请求的插件未获取到有效数据"); } return(retJson); } catch (Exception err) { //记录错误日志 //EFWCoreLib.CoreFrame.EntLib.ZhyContainer.CreateException().HandleException(err, "HISPolicy"); if (err.InnerException == null) { retJson = "{\"flag\":1,\"msg\":" + "\"" + err.Message + "\"" + "}"; if (para.iscompressjson) { retJson = ZipComporessor.Compress(retJson); } ShowHostMsg(Color.Red, DateTime.Now, "客户端[本地回调]执行失败:" + err.Message); return(retJson); } else { retJson = "{\"flag\":1,\"msg\":" + "\"" + err.InnerException.Message + "\"" + "}"; if (para.iscompressjson) { retJson = ZipComporessor.Compress(retJson); } ShowHostMsg(Color.Red, DateTime.Now, "客户端[本地回调]执行失败:" + err.InnerException.Message); return(retJson); } } }
/// <summary> /// 执行 /// </summary> /// <param name="isimmediately">是否马上</param> public void Excute(bool isimmediately) { if (taskConfig != null && (isimmediately == true || taskConfig.qswitch == true)) { try { MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Blue, string.Format("任务【{0}】准备开始执行...", taskConfig.taskname)); if (taskConfig.serialorparallel == 0)//串行 { foreach (var item in taskConfig.taskService) { MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Blue, string.Format("正在执行服务{0}/{1}/{2}/{3}", item.pluginname, item.controller, item.method, item.argument)); ServiceResponseData retjson = InvokeWcfService( item.pluginname , item.controller , item.method , (ClientRequestData request) => { request.SetJsonData(item.argument); }); string txtResult = retjson.GetJsonData(); MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Blue, string.Format("服务执行完成,返回结果:{0}", txtResult)); } taskConfig.exectimes += 1; MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Blue, string.Format("任务【{0}】执行完成!", taskConfig.taskname)); } else if (taskConfig.serialorparallel == 1)//并行 { List <Task> tasks = new List <Task>(); foreach (var item in taskConfig.taskService) { tasks.Add(Task.Factory.StartNew(() => { MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Blue, string.Format("正在执行服务{0}/{1}/{2}/{3}", item.pluginname, item.controller, item.method, item.argument)); ServiceResponseData retjson = InvokeWcfService( item.pluginname , item.controller , item.method , (ClientRequestData request) => { request.SetJsonData(item.argument); }); string txtResult = retjson.GetJsonData(); MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Blue, string.Format("服务执行完成,返回结果:{0}", txtResult)); })); } //并行执行 Task.Factory.ContinueWhenAll(tasks.ToArray(), completedTasks => { taskConfig.exectimes += 1; MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Blue, string.Format("任务【{0}】执行完成!", taskConfig.taskname)); }); } } catch (Exception err) { MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Red, string.Format("任务【{0}】执行出错!", taskConfig.taskname)); MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Red, err.Message + err.StackTrace); } } }
//执行服务核心方法 private static string ExecuteService(string plugin, string controller, string method, string jsondata, HeaderParameter para) { string retJson = null; try { #region 执行插件控制器的核心算法 object[] paramValue = null;//jsondata? ServiceResponseData retObj = null; //先解密再解压 string _jsondata = jsondata; //解密参数 if (para.isencryptionjson) { DESEncryptor des = new DESEncryptor(); des.InputString = _jsondata; des.DesDecrypt(); _jsondata = des.OutString; } //解压参数 if (para.iscompressjson) { _jsondata = ZipComporessor.Decompress(_jsondata); } ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype); requestData.SetJsonData(_jsondata); requestData.LoginRight = para.LoginRight; //获取插件服务 EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = CoreFrame.Init.AppPluginManage.PluginDic[plugin]; retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData); if (retObj != null) { retJson = retObj.GetJsonData(); } else { retObj = new ServiceResponseData(); retObj.Iscompressjson = para.iscompressjson; retObj.Isencryptionjson = para.isencryptionjson; retObj.Serializetype = para.serializetype; retJson = retObj.GetJsonData(); } retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}"; //先压缩再加密 //压缩结果 if (para.iscompressjson) { retJson = ZipComporessor.Compress(retJson); } //加密结果 if (para.isencryptionjson) { DESEncryptor des = new DESEncryptor(); des.InputString = retJson; des.DesEncrypt(); retJson = des.OutString; } #endregion return(retJson); } catch (Exception err) { throw err; } }