A simple example of WebService to XML

  • 2021-12-13 16:41:01
  • OfStack

A simple example of WebService to XML

Transmission

[WebMethod]


 public XmlDataDocument GetSiteAData(string AssignName)
  {
    XmlDataDocument xd = new XmlDataDocument();
    DataSet ds = BusinessWork.BusinessWorkDataSet("TreeView1");

      xd = new XmlDataDocument(ds);
      XmlNode root1 = xd.DocumentElement;
      XmlNodeList roots = root1.SelectNodes("url");
      foreach (XmlNode roota in roots) // Mark all elements with site names 
      {
        XmlElement Link = xd.CreateElement("SiteName");
        Link.InnerText = ConfigurationSettings.AppSettings["SiteName"].ToString();
        roota.AppendChild(Link);
      }
    return xd;
  }

Asynchronous invocation


  IAsyncResult ar1;
    IAsyncResult ar2;

    localhost.WebService serviceA = new localhost.WebService();
    XmlNode xmlNode1;
    XmlNode xmlNode2;


    //// Direct call 
    //xmlNode1 = serviceA.GetSiteAData("2");
    // Asynchronous invocation 
    ar1 = serviceA.BeginGetSiteAData("3", null, null);
    ar2 = serviceA.BeginGetSiteAData("2", null, null);
    xmlNode1 = serviceA.EndGetSiteAData(ar1);
    xmlNode2 = serviceA.EndGetSiteAData(ar2);

    StringBuilder xmlString1;
    xmlString1 = new StringBuilder(xmlNode1.OuterXml);

    XmlDataDocument xd = new XmlDataDocument();
    xd.LoadXml(xmlString1.ToString());

    DataSet ds = new DataSet();
    ds.ReadXml(new XmlNodeReader(xd));
    GridView1.DataSource = ds.Tables[0];
    GridView1.DataBind();

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: