我在WEBSERVICE中定义一个类 [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;
}但是我在客户端引用的时候出现问题:
无法将类型为“System.Xml.XmlElement”的对象强制转换为类型“System.Xml.XmlDocument”。
public void update()
{
WebSvs.Service1 webs = new WebSvs.Service1();
System.Xml.XmlDocument doc = ((System.Xml.XmlDocument)webs.GetUpdateData());
doc.Save(Application.StartupPath + @"\update.xml");
System.Diagnostics.Process.Start(Application.StartupPath + @"\update.exe");
Close();
Application.Exit();
}
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;
}但是我在客户端引用的时候出现问题:
无法将类型为“System.Xml.XmlElement”的对象强制转换为类型“System.Xml.XmlDocument”。
public void update()
{
WebSvs.Service1 webs = new WebSvs.Service1();
System.Xml.XmlDocument doc = ((System.Xml.XmlDocument)webs.GetUpdateData());
doc.Save(Application.StartupPath + @"\update.xml");
System.Diagnostics.Process.Start(Application.StartupPath + @"\update.exe");
Close();
Application.Exit();
}
解决方案 »
- WP7编程可以解决系统的这些问题吗?
- ASP.NET 实现多文件文件打包下载
- 可以将窗体,嵌入到一个窗体中吗?比如让主窗体的右侧,灵活的嵌入不同的其他窗体?
- (高手请进)如何复制一个treeview结点,来生成新的树节点?
- wpf能否通过代码布置页面
- 共享一个免费开源融合SNS+cms+bbs且框架可以用于商业
- 如何通过双击DataGrid上的某一行时将该行的所有数据提取出来?谢谢...
- PC的和PPC蓝牙开发
- 如何清空datatable中的image类型的字段?
- 能不能这样访问property?
- GridView编辑列的问题
- 请问visual studio 2008 c# 类视图在哪里调用出来显示啊?
public string 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.InnerXml;
} public void update()
{
WebSvs.Service1 webs = new WebSvs.Service1();
System.Xml.XmlDocument doc = new XmlDocument();[color]
string xml= webs.GetUpdateData();doc.LoadXml(xml);
doc.Save(Application.StartupPath + @"\update.xml");
System.Diagnostics.Process.Start(Application.StartupPath + @"\update.exe");
Close();
Application.Exit();
}
webservice最好不好返回引用的类型
不需要转换吧
System.Xml.XmlDocument doc = webs.GetUpdateData();
错误 1 无法将类型“System.Xml.XmlNode”隐式转换为“System.Xml.XmlDocument”。存在一个显式转换(是否缺少强制转换?) E:\temp\update\WindowsApplication1\WindowsApplication1\Form1.cs 40 42 WindowsApplication1