| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1093 人关注过本帖
标题:webservice自动更新
只看楼主 加入收藏
reandy
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-10-15
收藏
 问题点数:0 回复次数:2 
webservice自动更新
有没有高手做过自动更新下载
下面是原代码,但是在做实验的时候总是出错。希望有高手指点具体步骤:
[bold]2、WebServices的GetVer方法。
[/bold]        [WebMethod(Description="取得更新版本")]        public string GetVer()        {            XmlDocument doc = new XmlDocument();            doc.Load(Server.MapPath("update.xml"));            XmlElement root = doc.DocumentElement;            return root.SelectSingleNode("version").InnerText;        }


     [bold]3、WebServices的GetUpdateData方法。[/bold]
        [WebMethod(Description="在线更新软件")]        [SoapHeader("sHeader")]        public System.Xml.XmlDocument GetUpdateData()        {            //验证用户是否登陆            if(sHeader==null)                return null;            if(!DataProvider.GetInstance.CheckLogin(sHeader.Username,sHeader.Password))                return null;            //取得更新的xml模板内容            XmlDocument doc = new XmlDocument();            doc.Load(Server.MapPath("update.xml"));            XmlElement root = doc.DocumentElement;            //看看有几个文件需要更新            XmlNode updateNode = root.SelectSingleNode("filelist");             string path = updateNode.Attributes["sourcepath"].Value;            int count = int.Parse(updateNode.Attributes["count"].Value);            //将xml中的value用实际内容替换            for(int i=0;i<count;i++)            {                XmlNode itemNode = updateNode.ChildNodes[i];                string fileName = path + itemNode.Attributes["name"].Value;                FileStream fs = File.OpenRead(Server.MapPath(fileName));                itemNode.Attributes["size"].Value = fs.Length.ToString();                BinaryReader br = new BinaryReader(fs);                //这里是文件的实际内容,使用了Base64String编码                itemNode.SelectSingleNode("value").InnerText = Convert.ToBase64String(br.ReadBytes((int)fs.Length),0,(int)fs.Length);                br.Close();                fs.Close();            }            return doc;        }    [bold]4、在客户端进行的工作。[/bold]
      首先引用此WebServices,例如命名为:WebSvs,
     string nVer = Start.GetService.GetVer(); 
     if(Application.(nVer)<=0)
      update();

  在本代码中 Start.GetService是WebSvs的一个Static 实例。首先检查版本,将结果与当前版本进行比较,
如果为新版本则执行UpDate方法。

        void update()        {            this.statusBarPanel1.Text = "正在下载...";            System.Xml.XmlDocument doc = ((System.Xml.XmlDocument)Start.GetService.GetUpdateData());            doc.Save(Application.StartupPath + @"\update.xml");            System.Diagnostics.Process.Start(Application.StartupPath + @"\update.exe");            Close();            Application.Exit();        }
这里为了简单起见,没有使用异步方法,当然使用异步方法能更好的提高客户体验,这个需要读者们自己去添加。
:) update的作用是将升级的XML文件下载下来,保存为执行文件目录下的一个Update.xml文件。任务完成,
退出程序,等待Update.Exe 来进行升级。     [bold]5、Update.Exe 的内容。[/bold]         private void Form1_Load(object sender, System.EventArgs e)        {            System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcesses();            foreach(System.Diagnostics.Process p in ps)            {                //MessageBox.Show(p.ProcessName);                if(p.ProcessName.ToLower()=="customerapplication")                {                    p.Kill();                    break;                }            }            XmlDocument doc = new XmlDocument();            doc.Load(Application.StartupPath + @"\update.xml");            XmlElement root = doc.DocumentElement;            XmlNode updateNode = root.SelectSingleNode("filelist");            string path = updateNode.Attributes["sourcepath"].Value;            int count = int.Parse(updateNode.Attributes["count"].Value);            for(int i=0;i<count;i++)            {                XmlNode itemNode = updateNode.ChildNodes[i];                string fileName = itemNode.Attributes["name"].Value;                FileInfo fi = new FileInfo(fileName);                fi.Delete();                //File.Delete(Application.StartupPath + @"\" + fileName);                this.label1.Text = "正在更新: " + fileName + " (" + itemNode.Attributes["size"].Value + ") ...";                FileStream fs = File.Open(fileName,FileMode.Create,FileAccess.Write);                fs.Write(System.Convert.FromBase64String(itemNode.SelectSingleNode("value").InnerText),0,int.Parse(itemNode.Attributes["size"].Value));                fs.Close();            }            label1.Text = "更新完成";            File.Delete(Application.StartupPath + @"\update.xml");            label1.Text = "正在重新启动应用程序...";            System.Diagnostics.Process.Start("CustomerApplication.exe");            Close();            Application.Exit();        }
搜索更多相关主题的帖子: webservice 自动 
2007-11-25 21:01
sa481453
Rank: 2
等 级:论坛游民
帖 子:37
专家分:74
注 册:2006-9-16
收藏
得分:0 
这代码帖的可构乱的,我做过,但大家方法不同
2007-11-26 14:42
reandy
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-10-15
收藏
得分:0 
请问你是用什么方法作的
2007-11-26 22:05
快速回复:webservice自动更新
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021407 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved