WebService传XML 简单实例

时间:2021-05-26

WebService传XML 简单实例

传送

[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) //为所有元素加上站点名称标记 { XmlElement Link = xd.CreateElement("SiteName"); Link.InnerText = ConfigurationSettings.AppSettings["SiteName"].ToString(); roota.AppendChild(Link); } return xd; }

异步调用

IAsyncResult ar1; IAsyncResult ar2; localhost.WebService serviceA = new localhost.WebService(); XmlNode xmlNode1; XmlNode xmlNode2; ////直接调用 //xmlNode1 = serviceA.GetSiteAData("2"); //异步调用 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();

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章