SilverLight中用实体类访问WebService的方法

SilverLight中用实体类访问WebService的方法,第1张

概述SilverLight工程中调用方法 ---------------------------------------------------- private void Uc_UserManager_Loaded(object sender, RoutedEventArgs e)         {             //Id,UserGroupId,Name,AliasName,Sex,P

Silverlight工程中调用方法

----------------------------------------------------

private voID Uc_UserManager_Loaded(object sender,RoutedEventArgs e)
        {
            //ID,UserGroupID,name,Aliasname,Sex,Password,Locked,Description
            //string sqlquery = "select * from User";
            DbServiceSoapClIEnt dbs = ServiceUtil.GetDynamicclIEnt();
            dbs.GetALLUsersAsync();
            dbs.GetALLUsersCompleted += new EventHandler<GetALLUsersCompletedEventArgs>(dbs_GetALLUsersCompleted);
           
            //dbs.GetDatatableAsync(sqlquery);
            //dbs.GetDatatableCompleted += new EventHandler<GetDatatableCompletedEventArgs>(dbs_GetDatatableCompleted);

        }

 

private voID dbs_GetALLUsersCompleted(object sender,GetALLUsersCompletedEventArgs e)
        {
            User[] userArray=e.Result;

            this.dataGrID1.ItemsSource = userArray;
           
        }

 

WebSerivce定义方法

------------------------------------------------

[WebMethod]
        public User[] GetALLUsers()
        {
            return UserService.GetAllUsers();
        }

 

public static class UserService
    {
        public static User[] GetAllUsers()
        {
            List<User> UserList = new List<User>();
            string x = "select * from User ";
            Datatable dt = DbConnPool.DBWrap.ExecuteDatatable(x);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DaTarow dr in dt.Rows)
                {
                    //ID,Description
                    User user = new User();
                    user.ID = dr["ID"].ToString();
                    user.UserGroupID = dr["UserGroupID"].ToString();
                    user.name = dr["name"].ToString();
                    user.Aliasname = dr["Aliasname"].ToString();
                    //user.Sex = dr["Sex"].ToString();
                    user.Password = dr["Password"].ToString();
                    //user.Locked = dr["Locked"].ToString();
                    user.Description = dr["Description"].ToString();
                    UserList.Add(user);
                }
            }
            if (dt != null)
            {
                dt.dispose();
                dt = null;
            }
            return UserList.ToArray();
        }

}

 

定义实体类

-------------------------------------------------------------------

[Serializable]
    public class User
    {
        //ID,Description
        private string m_ID = "";

        public string ID
        {
            get { return m_ID; }
            set { m_ID = value; }
        }
        private string m_UserGroupID = "";

        public string UserGroupID
        {
            get { return m_UserGroupID; }
            set { m_UserGroupID = value; }
        }
        private string m_name = "";

        public string name
        {
            get { return m_name; }
            set { m_name = value; }
        }
        private string m_Aliasname = "";

        public string Aliasname
        {
            get { return m_Aliasname; }
            set { m_Aliasname = value; }
        }
        private bool m_Sex = false;

        public bool Sex
        {
            get { return m_Sex; }
            set { m_Sex = value; }
        }
        private string m_Password = "";

        public string Password
        {
            get { return m_Password; }
            set { m_Password = value; }
        }
        private bool m_Locked = false;

        public bool Locked
        {
            get { return m_Locked; }
            set { m_Locked = value; }
        }
        private string m_Description = "";

        public string Description
        {
            get { return m_Description; }
            set { m_Description = value; }
        }

        //----    }

总结

以上是内存溢出为你收集整理的SilverLight中用实体类访问WebService的方法全部内容,希望文章能够帮你解决SilverLight中用实体类访问WebService的方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1032703.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存