WebService passing XML data c#dataset operation XML parsing webservice returned XML data

Source: Internet
Author: User

The data passed by WebService can only be serialized data, typically XML data.

      /// <summary>

         /// 通过用户名和密码 返回下行数据          /// </summary>          /// <param name="UserName">用户名</param>          /// <param name="UserPwd">密码</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 //如果需要修改xml里的数据  需要加上这句                          foreach (XmlNode node in list)                          {                              //这里是修改XML中 RecordDate的时间格式 原始格式是:  <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 returns XML data, parses XML data, and binds 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();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.