The data transmitted by Webservice can only be serialized data, typically xml data.
// <Summary> /// return downstream data using the user name and password /// </summary> /// <param name = "UserName"> User name </param> // /<param name = "UserPwd"> password </param> // <returns> </returns> [WebMethod] public XmlDataDocument GetUpMassageDate (string UserName, string UserPwd) {try {XmlDataDocument xd = new XmlDataDocument (); DataSet ds = DbHelperSQL. query ("select Mobile, UPMessge, RecordDate from dbo. NA_Activity_Data where ActivityID in (se Lect ActivityID from dbo. NA_Activity where UserID in (select UserID from dbo. NA_User where UserName = '"+ UserName. trim () + "'and UserPwd ='" + UserPwd. trim () + "')"); if (ds! = Null & ds. tables. count> 0) {xd = new XmlDataDocument (ds); XmlNode root1 = xd. documentElement; XmlNodeList roots = root1.SelectNodes ("ds"); foreach (XmlNode item in roots) {XmlNodeList list = item. selectNodes ("RecordDate"); ds. enforceConstraints = false; // Add this foreach (XmlNode node in list) if you need to modify the data in xml {// here is the original format of modifying the RecordDate time format in XML: <RecordDate> 2012-04-20T16: 16: 00 + 08: 00 </RecordDate> Node. innerText = Convert. toDateTime (node. innerText. toString ()). toString ("yyyy-MM-dd HH: mm") ;}} return xd ;}else {return null ;}} catch (Exception ex) {return null ;}} /// <summary> /// return downstream data using the user name and password /// </summary> /// <param name = "UserName"> User name </param>/ // <param name = "UserPwd"> password </param> // <returns> </returns> [WebMethod] public XmlDataDocument GetUpMassageDate (string UserName, string UserPwd) {try {XmlDataDocument xd = new XmlDataDocument (); DataSet ds = DbHelperSQL. query ("select Mobile, UPMessge, RecordDate from dbo. NA_Activity_Data where ActivityID in (select ActivityID from dbo. NA_Activity where UserID in (select UserID from dbo. NA_User where UserName = '"+ UserName. trim () + "'and UserPwd ='" + UserPwd. trim () + "')"); if (ds! = Null & ds. tables. count> 0) {xd = new XmlDataDocument (ds); XmlNode root1 = xd. documentElement; XmlNodeList roots = root1.SelectNodes ("ds"); foreach (XmlNode item in roots) {XmlNodeList list = item. selectNodes ("RecordDate"); ds. enforceConstraints = false; // Add this foreach (XmlNode node in list) if you need to modify the data in xml {// here is the original format of modifying the RecordDate time format in XML: <RecordDate> 2012-04-20T16: 16: 00 + 08: 00 </RecordDate> node. innerText = Convert. toDateTime (node. innerText. toString ()). toString ("yyyy-MM-dd HH: mm") ;}} return xd ;}else {return null ;}} catch (Exception ex) {return null ;}}
Reference webservice to return XML data, parse XML data and bind it to the GridView
public void DateBind() { UpMassgeWebserive.GetDateUpMassageSoapClient um = new UpMassgeWebserive.GetDateUpMassageSoapClient(); DataSet ds = new DataSet(); XmlNode xmlNode1; XmlDataDocument xd = new XmlDataDocument(); StringBuilder sb; xmlNode1 = um.GetUpMassageDate("hzh", "chinahzh"); if (xmlNode1==null) { return; } sb = new StringBuilder(xmlNode1.OuterXml); if (sb.ToString().Equals("")) { return; } xd.LoadXml(sb.ToString()); ds.ReadXml(new XmlNodeReader(xd)); GridView1.DataSource = ds.Tables[0].DefaultView; GridView1.DataBind();