コード例 #1
0
ファイル: WebservicesHelper.cs プロジェクト: vijju1608/VRF
 /*
  *  调用实例
  *   object[] args = new object[1];
  *    args[0] = planid;
  *    object result = WebservicesHelper.InvokeWebService("http://c-wuxts01:8888/PRM_API/PRM_API.asmx", "Return_PlanData", args);
  *   return (DataSet)result;
  */
 /// < summary>
 /// 动态调用web服务
 /// < /summary>
 /// < param name="url">WSDL服务地址< /param>
 /// < param name="methodname">方法名< /param>
 /// < param name="args">参数< /param>
 /// < returns>< /returns>
 public static object InvokeWebService(string url, string methodname, object[] args)
 {
     try
     {
         return(WebservicesHelper.InvokeWebService(url, null, methodname, args));
     }
     catch (Exception ex)
     {
         LogHelp.WriteLog("InvokeWebService异常,url:" + url + "methodname" + methodname, ex);
         return(null);
     }
 }
コード例 #2
0
        private void AutoUpdate()
        {
            //调用函数
            //参数集合
            try
            {
                string version = MyConfig.Version;
                if (version != null)
                {
                    //去掉version中的非数字字符
                    string lastch = version.Substring(version.Length - 1, 1);
                    while (string.CompareOrdinal(lastch, "0") < 0 || string.CompareOrdinal(lastch, "9") > 0)
                    {
                        version = version.Remove(version.Length - 1);
                        lastch  = version.Substring(version.Length - 1, 1);
                    }
                    ////去掉version中的最后一个".",如将3.2.0变为3.20,不然更新服务器不识别版本 by Yunxiao Lin 20180526
                    //string[] versionNumbers = version.Split('.');
                    //if (versionNumbers.Count() == 3)
                    //    version = versionNumbers[0] + "." + versionNumbers[1] + versionNumbers[2];
                }
                object[] args = new object[4];
                args[0] = version;
                if (Registration.IsSuperUser())
                {
                    args[1] = "All"; //注意All必须第一个字母大写,后面的小写,不然不更新。
                }
                else
                {
                    args[1] = Registration.GetRegionCode();
                }
                args[2] = "VRF";
                string        file   = "PatchUpdate.exe";
                Configuration config = ConfigurationManager.OpenExeConfiguration(Application.StartupPath + @"\" + file);
                if (config.AppSettings.Settings["FileType"] == null)
                {
                    return;
                }
                args[3] = config.AppSettings.Settings["FileType"].Value.ToString();

                //20180628 更新服务接口配置文件结构变更 20180628 by Yunxiao Lin
                var kWSRoot    = config.AppSettings.Settings["WSPath"];
                var kPatchPath = config.AppSettings.Settings["RootPath"];
                var kIps       = config.AppSettings.Settings["IpList"];
                var kTimeOut   = config.AppSettings.Settings["TimeOut"];
                if (kWSRoot == null || kPatchPath == null || kIps == null || kTimeOut == null)
                {
                    return;
                }

                string WSRoot    = kWSRoot.Value.ToString();             //webservics地址
                string PatchPath = kPatchPath.Value.ToString();          //补丁下载路径
                string Ips       = kIps.Value.ToString();                //ip集合
                int    TimeOut   = int.Parse(kTimeOut.Value.ToString()); //链接超时

                List <string> IpList       = Ips.ToString().Split(';').ToList();
                bool          HasConifgrue = false;
                //在连接之前先ping
                foreach (string ip in IpList)
                {
                    if (ip != "" && Ping(ip, TimeOut))
                    {
                        WSRoot       = string.Format(WSRoot, ip);
                        PatchPath    = string.Format(PatchPath, ip);
                        HasConifgrue = true;
                        break;
                    }
                }
                //如果都ping不通则退出更新
                if (!HasConifgrue)
                {
                    return;
                }

                //设置参数
                string pargs = args[0] + " " + args[1] + " " + args[2];

                //添加代理,不然在外网会连不上服务
                System.Net.WebProxy webProxy = new System.Net.WebProxy(WSRoot, true);
                webProxy.Credentials = new System.Net.NetworkCredential("1", "1");
                System.Net.WebRequest.DefaultWebProxy = webProxy;

                //连接服务
                object result = WebservicesHelper.InvokeWebService(WSRoot, "HasPatch", args);

                if (result != null)
                {
                    bool HasPatch = (bool)result;
                    if (HasPatch)
                    {
                        //启动自动更新客户端
                        //MessageBox.Show("AutoUpdate");
                        Process.Start(Application.StartupPath + @"\" + file, pargs);
                        //Process.Start(@"C:\SVN\GVRF\DesktopVRF\PatchUpdate\bin\Debug\"+file, pargs);
                        //Process.Start(@"C:\SVN\GVRF\DesktopVRF\PatchUpdate\bin\Debug\" + file);
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }