【问题标题】:need to use an asmx webservice(wsdl) in c# to update and delete from this xml file需要在 c# 中使用 asmx webservice(wsdl) 来更新和删除这个 xml 文件
【发布时间】:2017-10-27 15:45:48
【问题描述】:

我需要在 c# 中使用 asmx webservice(wsdl) 来更新和删除这个 xml 文件

enter code here

<?xml version="1.0" encoding="utf-8"?>
<StudentRecords>
<student>
<id>1</id>
<cohort>BSE</cohort>`enter code here`
<firstname>Sherlock</firstname>
<lastname>Holmes</lastname>
<address>United Kingdom</address>
</student>

<student>
<id>2</id>
<cohort>BSE</cohort>
<firstname>Tom</firstname>
<lastname>Hanks</lastname>
<address>United Kingdom</address>
</student>
</StudentRecords>

【问题讨论】:

  • 有什么问题!
  • 问题是我需要在 c# 中使用 wsdl 创建一个 web 服务来添加、更新和删除新元素(在这种情况下是学生)。到目前为止,设法在客户端页面中添加和使用......我坚持更新和删除
  • 哪些元素需要更新?您需要删除所有学生还是仅删除特定学生。
  • 实际上是一个学生..onclick 事件将使用这种编辑或删除方法...当我单击它时,它会在 web 服务中调用该方法并编辑或删除一个学生(客户端中的 gridview)跨度>

标签: c# xml visual-studio wsdl asmx


【解决方案1】:

使用此方法添加 enter code here

      [WebMethod]
      public string Insert(string i, string c, string f, string l, string a)
      {

        XmlDocument xl = new XmlDocument();
        xl.Load(Server.MapPath("~/student.xml"));

        XmlElement parent = xl.CreateElement("student");
        XmlElement id = xl.CreateElement("id");
        XmlElement cohort = xl.CreateElement("cohort");
        XmlElement fname = xl.CreateElement("firstname");
        XmlElement lname = xl.CreateElement("lastname");
        XmlElement add = xl.CreateElement("address");

        id.InnerText = i;
        cohort.InnerText = c;
        fname.InnerText = f;
        lname.InnerText = l;
        add.InnerText = a;

        parent.AppendChild(id);
        parent.AppendChild(cohort);
        parent.AppendChild(fname);
        parent.AppendChild(lname);
        parent.AppendChild(add);

        xl.DocumentElement.AppendChild(parent);
        xl.Save(Server.MapPath("~/student.xml"));
        LoadData();



        return i.ToString()+ c.ToString() + f.ToString() + l.ToString() + 
        a.ToString();
       }

【讨论】:

    猜你喜欢
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    相关资源
    最近更新 更多