private bool ServiceExists() { int clientStoreID = Convert.ToInt32(MQC_Service.Properties.Settings.Default.ClientStoreID); //MQCWS.MQC_WebService ws = new MQCWS.MQC_WebService(); try { object[] args = new object[1]; args[0] = clientStoreID; string strText = (string)WebServiceHelper.Function(tb_wsurl.Text.Trim(), "HaveFile", args); //ws.Url = tb_wsurl.Text.Trim(); //string strTest = ws.HaveFile(clientStoreID); return(true); } catch { return(false); } }
private void Client_GetFile(string filePath) { object[] args = new object[1]; try { System.IO.FileStream fsl = null; byte[] bl = null; args[0] = filePath; bl = (byte[])WebServiceHelper.Function(url, "DownloadFile", args); fsl = new FileStream(clientDest + Get_File_Name(filePath), FileMode.Create); fsl.Write(bl, 0, bl.Length); fsl.Close(); fsl = null; } catch (Exception ex) { MessageBox.Show(ex.Message); //IsRunning = false; return; } finally { bool isRemoved = (bool)WebServiceHelper.Function(url, "RemoveFile", args); if (isRemoved) { object[] args2 = new object[3]; args2[0] = clientStoreID; args2[1] = 0; args2[2] = Get_File_Name(filePath) + " download completed."; WebServiceHelper.Function(url, "WriteLog", args2); } else { MessageBox.Show("Fail to remove file from server."); } } }
public static object InvokeWebService(string url, string classname, string methodname) { string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling"; if ((classname == null) || (classname == "")) { classname = WebServiceHelper.GetWsClassName(url); } try { //获取WSDL WebClient wc = new WebClient(); Stream stream = wc.OpenRead(url + "?WSDL"); ServiceDescription sd = ServiceDescription.Read(stream); ServiceDescriptionImporter sdi = new ServiceDescriptionImporter(); sdi.AddServiceDescription(sd, "", ""); CodeNamespace cn = new CodeNamespace(@namespace); //生成客户端代理类代码 CodeCompileUnit ccu = new CodeCompileUnit(); ccu.Namespaces.Add(cn); sdi.Import(cn, ccu); CSharpCodeProvider csc = new CSharpCodeProvider(); ICodeCompiler icc = csc.CreateCompiler(); //设定编译参数 CompilerParameters cplist = new CompilerParameters(); cplist.GenerateExecutable = false; cplist.GenerateInMemory = true; cplist.ReferencedAssemblies.Add("System.dll"); cplist.ReferencedAssemblies.Add("System.XML.dll"); cplist.ReferencedAssemblies.Add("System.Web.Services.dll"); cplist.ReferencedAssemblies.Add("System.Data.dll"); //编译代理类 CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu); if (true == cr.Errors.HasErrors) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors) { sb.Append(ce.ToString()); sb.Append(System.Environment.NewLine); } throw new Exception(sb.ToString()); } //生成代理实例,并调用方法 System.Reflection.Assembly assembly = cr.CompiledAssembly; Type t = assembly.GetType(@namespace + "." + classname, true, true); object obj = Activator.CreateInstance(t); System.Reflection.MethodInfo mi = t.GetMethod(methodname); wc.Dispose(); stream.Close(); stream.Dispose(); return(mi.Invoke(obj, null)); } catch (Exception ex) { return(null); //throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace)); } }
//动态调用web服务 public static object InvokeWebService(string url, string methodname) { return(WebServiceHelper.InvokeWebService(url, null, methodname)); }
private void TimerProcessor(Object myObject, EventArgs e) { timer.Stop(); ClearMemory(); Int32 IsServer = Convert.ToInt32(MQC_Service.Properties.Settings.Default.IsServer); if (IsServer == 1) { string str_SQL = "SELECT distinct mqc_bt_loc_id, mqc_loc_filepath " + "FROM t_mqc_batch, t_mqc_loc " + "WHERE mqc_bt_cmpl_time IS NULL AND mqc_bt_loc_id = mqc_loc_id"; DataTable dt_loc_list; DataAccess da; try { da = new DataAccess(connString); dt_loc_list = da.GetDataTable(str_SQL); if (dt_loc_list.Rows.Count != 0) { foreach (DataRow row in dt_loc_list.Rows) { CreateBatchXML(row[0].ToString(), row[1].ToString()); } } } catch (System.Exception ex) { writeLog(ex.Message.Replace("\n", " ")); } } else { DownFile downfile = new DownFile(); downfile.ftpDownFile(@"/public_html/temp.pdf", @"c:/temp.pdf", @"/public_html"); if (clientDest == "" || !Directory.Exists(clientDest)) { MessageBox.Show("There is no local folder!"); return; } if (url.Trim() == "") { MessageBox.Show("WebService dose not exist!"); return; } object[] args = new object[1]; args[0] = clientStoreID; string filePath = (string)WebServiceHelper.Function(url, "HaveFile", args); if (filePath == "") { timer.Enabled = true; return; } else { Client_GetFile(filePath);// Check and Get file from server if (firstRun) { Insert_SysBatch(); firstRun = false; } Client_UpdateDB(); } timer.Enabled = true; } }