今天写了个测试自动升级的WebService,  可以看下。
为什么GetUpdateData()返回的不是System.Xml.XmlDocument  而是System.Xml.XmlNode
WebService改过之后再更新还不行。。
这个还有问题。。 [WebMethod(Description = "在线更新软件")]
        public System.Xml.XmlDocument GetUpdateData()
        {
            //取得更新的xml模板内容
            XmlDocument doc = new XmlDocument();
             //处理操作
            return doc;
        }

解决方案 »

  1.   

    这个方法全部代码[WebMethod(Description = "在线更新软件")]
            public System.Xml.XmlDocument GetUpdateData()
            {
                //取得更新的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;
            }
      

  2.   

    调用的时候System.Xml.XmlDocument doc = test.GetUpdateData();
    一直都是编译错误。。
    System.Xml.XmlNode”隐式转换为“System.Xml.XmlDocument”。存在一个显式转换(是否缺少强制转换?)
    我都不知道XmlNode在那里来的。
      

  3.   

    我好像明白了点。
    转到定义就是返回的xmlNode
     public System.Xml.XmlNode GetUpdateData() {
                object[] results = this.Invoke("GetUpdateData", new object[0]);
                return ((System.Xml.XmlNode)(results[0]));
            }