C# 从WebService方法编辑XML文档

C# 从WebService方法编辑XML文档,c#,xml,web-services,C#,Xml,Web Services,我有一个使用XML文档的Web服务,我正在尝试添加一个函数,在XML文档中添加一个新节点。它运行正常,没有中断,但保存功能似乎不起作用?这是代码 [WebMethod] public void AddNodeTEST() { XmlDocument xmlUpdateCfg = new XmlDocument(); try { xmlUpdateCfg.Load(Context.Request.MapPath("Updates.xml")); }

我有一个使用XML文档的Web服务,我正在尝试添加一个函数,在XML文档中添加一个新节点。它运行正常,没有中断,但保存功能似乎不起作用?这是代码

[WebMethod]
public void AddNodeTEST()
{
    XmlDocument xmlUpdateCfg = new XmlDocument();

    try
    {
        xmlUpdateCfg.Load(Context.Request.MapPath("Updates.xml"));
    }
    catch (Exception ex)
    {

    }

    XmlNode updateInfo = xmlUpdateCfg.SelectSingleNode("updateinfo");

    /* Create the downloadmodule node */
    XmlNode newDownloadModule = xmlUpdateCfg.CreateNode(XmlNodeType.Element, "downloadmodule", null);
    newDownloadModule.InnerText = "download/test.CAB";
    XmlAttribute downloadModuleName = xmlUpdateCfg.CreateAttribute("name");
    downloadModuleName.Value = "Test";
    newDownloadModule.Attributes.Append(downloadModuleName);

    /* Create the version node */
    XmlNode newVersion = xmlUpdateCfg.CreateNode(XmlNodeType.Element, "version", null);
    XmlAttribute versionMaj = xmlUpdateCfg.CreateAttribute("maj");
    versionMaj.Value = "1";
    XmlAttribute versionMin = xmlUpdateCfg.CreateAttribute("min");
    versionMin.Value = "2";
    XmlAttribute versionBld = xmlUpdateCfg.CreateAttribute("bld");
    versionBld.Value = "3";
    XmlAttribute versionRev = xmlUpdateCfg.CreateAttribute("rev");
    versionRev.Value = "4";
    newVersion.Attributes.Append(versionMaj);
    newVersion.Attributes.Append(versionMin);
    newVersion.Attributes.Append(versionBld);
    newVersion.Attributes.Append(versionRev);

    /* Add the newVersion node to the newDownloadModule node */
    newDownloadModule.AppendChild(newVersion);

    /* Add the newDownloadModule to the updateinfo Node*/
    updateInfo.AppendChild(newDownloadModule);

    xmlUpdateCfg.Save("Updates.xml");
}
这里是XML结构

<?xml version="1.0" encoding="utf-8" ?>
<updateinfo>
  <downloadmodule name="test">
    <version maj="1" min="0" bld="4" rev="0"/>
    Download/cabfile.CAB
  </downloadmodule>
</updateinfo>

下载/cabfile.CAB

非常感谢您的帮助,谢谢

是否应该调用xmlUpdateCfg.Save(Context.Request.MapPath(“Updates.xml”))以便它将其保存到读取它的相同位置?

xmlUpdateCfg.Save(Context.Request.MapPath(“Updates.xml”);我也试过了,但上面说我得等6分钟左右!