码迷,mamicode.com
首页 > Web开发 > 详细

WebService传递XML数据 C#DataSet操作XML 解析WebService返回的XML数据

时间:2014-06-25 21:57:33      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:des   class   code   ext   color   com   

Webservice传递的数据只能是序列化的数据,典型的就是xml数据。

 

      /// <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;
            }
        }
 
引用webservice返回XML数据,解析XML数据并绑定到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();

WebService传递XML数据 C#DataSet操作XML 解析WebService返回的XML数据,布布扣,bubuko.com

WebService传递XML数据 C#DataSet操作XML 解析WebService返回的XML数据

标签:des   class   code   ext   color   com   

原文地址:http://www.cnblogs.com/iwin9999/p/3804616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!