none
remoting客户端数据如何提交服务器并存储到数据库表中? RRS feed

  • 问题

  • 如果我的客户端程序是个Winforms,并且有几个文本框控件,需要提交到服务器调用远程对象进行处理再存入数据库表中,这是怎么处理实现的?如果反向地客户端请查询数据库中的数据并发送到客户端上来这一系列地动作又是如何实现地?另外这些提交的表单数据是不是还要经过进行序列化?(再好能写出重点作用的代码给我参考一下)
    PS:我的问题有点多,请老师耐心解答!
    远程对象:
    namespace user
    {
       
            [Serializable]
            public class userDetail
            {
                private string userID;
                private string userName;
                private DateTime userBorthday;
                private string userTel;
                private string userAddress;
                private string userSexy;
                //添加构造函数的实例;
               
                public userDetail()
                { }
                public string Userid
                {
                    get { return userID; }
                    set { userID = value; }
                }
                public string Username
                {
                    get { return userName; }
                    set { userName = value; }
                }
    ............
    public class addUser: MarshalByRefObject
        {
             
            private SqlConnection sqlconn;
           
            public userDetail requeryUS(string userID)
            {
                userDetail users = new userDetail();
                sqlconn = new SqlConnection(ConfigurationManager.AppSettings["connectionString"]);
                sqlconn.Open();

                SqlParameter parUserid = new SqlParameter("@userID", SqlDbType.NChar);
                parUserid.Value =userID.ToString();
    SqlCommand sqlcomm = new SqlCommand("addUser", sqlconn);
                sqlcomm.CommandType = CommandType.StoredProcedure;
                sqlcomm.Parameters.Add(parUserid);
    sqlcomm.ExecuteNonQuery();
    sqlconn.Close();
                return users;
    客户端:
    namespace RemotingClient
    {
        public partial class Connect : Form
        {private void button1_Click(object sender, EventArgs e)
            {
                TcpChannel chan = new TcpChannel();
                ChannelServices.RegisterChannel(chan,false);
               addUser obj = (addUser)Activator.GetObject(typeof(addUser),"tcp://localhost:9500/addUser");
    userDetail users = obj.requeryUS(TBuserid.Text);
    }
    ........
    服务端:
    namespace RemoteService
    {
        public partial class Services :Form
        {private void ServiceBut_Click(object sender, EventArgs e)
            {
                TcpChannel chan = new TcpChannel(9500);
    ChannelServices.RegisterChannel(chan,false);
                RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(addUser),"addUser",WellKnownObjectMode.SingleCall);
    }
    .....................

    2009年4月23日 2:36

答案

  • 你好,关于你的问题下面的地址有较详细的说明及示例, http://msdn.microsoft.com/zh-cn/library/ms998525.aspx
    你还可以通过 WebCast 的 Remoting 系统课程了解到更详细的信息和更多的示例
    http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032328369&EventCategory=3&culture=zh-CN&CountryCode=CN


    知识改变命运,奋斗成就人生!
    2009年4月23日 16:39
    版主