类似于java中的EJB

解决方案 »

  1.   

    刚刚才写的一个! 服务器和客户端需要引用“类文件”   和System.Runtime.Remoting; 类文件 
    -------------- 
    using   System; 
    using   System.Collections.Generic; 
    using   System.Text; 
    using   System.Data; 
    using   System.Data.SqlClient; 
    namespace   db 

            public   class   DBAccess:MarshalByRefObject 
            { 
                    private   SqlConnection   con; 
                    private   SqlDataAdapter   da; 
                    private   DataSet   ds; 
                    public   DBAccess() 
                    { 
                            Console.Write( "构造方法 "); 
                    }                 public   DataSet   GetDateSet(string   strSql,string   tabName) 
                    { 
                            con   =   new   SqlConnection( "server=(local); "   +   "integrated   security=SSPI; "   +   "database=henry "); 
                            da   =   new   SqlDataAdapter(strSql,   con); 
                            SqlCommandBuilder   builder   =   new   SqlCommandBuilder(da); 
                            ds   =   new   DataSet(); 
                            da.Fill(ds,tabName); 
                            return   ds; 
                    }                 public   override   object   InitializeLifetimeService() 
                    { 
                            return   null; 
                    } 
            } 

    -------------------------------------- 服务器文件 
    -------------------------------------- using   System; 
    using   System.Collections.Generic; 
    using   System.ComponentModel; 
    using   System.Data; 
    using   System.Drawing; 
    using   System.Text; 
    using   System.Windows.Forms; 
    using   System.Runtime; 
    using   System.Runtime.Remoting; 
    using   System.Runtime.Remoting.Channels; 
    using   System.Runtime.Remoting.Channels.Tcp; 
    namespace   db 

            public   partial   class   Form1   :   Form 
            { 
                    public   Form1() 
                    { 
                            InitializeComponent(); 
                    }                 private   DBAccess   obj; 
                    private   void   Form1_Load(object   sender,   EventArgs   e) 
                    { 
                            TcpServerChannel   channel   =   new   TcpServerChannel(8888); 
                            ChannelServices.RegisterChannel(channel,   false); 
                            RemotingConfiguration.RegisterWellKnownServiceType(typeof(DBAccess),   "Hi ",   WellKnownObjectMode.Singleton); 
                            
                    } 
            } 
    } ------------------------------------------------------ 客户端代码     form1 
    --------------------------------------------------- 
    using   System; 
    using   System.Collections.Generic; 
    using   System.ComponentModel; 
    using   System.Data; 
    using   System.Drawing; 
    using   System.Text; 
    using   System.Windows.Forms; 
    using   System.Runtime; 
    using   System.Runtime.Remoting; 
    using   System.Runtime.Remoting.Channels; 
    using   System.Runtime.Remoting.Channels.Tcp; 
    namespace   db 

            public   partial   class   Form1   :   Form 
            { 
                    public   Form1() 
                    { 
                            InitializeComponent(); 
                    }                 private   DBAccess   obj; 
                    private   void   Form1_Load(object   sender,   EventArgs   e) 
                    { 
                            TcpClientChannel   channle   =   new   TcpClientChannel(); 
                            obj   =   (DBAccess)Activator.GetObject(typeof(DBAccess),   "tcp:/服务器的ip地址:8888/Hi "); 
                            dataGrid1.DataSource   =   obj.GetDateSet( "select   *   from   login ",   "login "); 
                            dataGrid1.DataMember   =   "login "; 
                            
                    } 
            } 

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

  2.   

    Remoting,Socket,WebService都可否分布式?
      

  3.   

    Remoting,WebService就可以做分布式开发。
      

  4.   

    无法创建连接到 URL“tcp:/127.0.0.1:8888/Hi ”的信道接收器。可能尚未注册适当的信道。
    是什么原因?
      

  5.   

    分布式开发将一个系统分为三个层次:客户端应用程序,应用程序服务器,后台数据库。客户端提出请求,应用服务器接受请求并处理然后返回数据给客户端,后台数据库当然是提供数据。多半是用于WEB开发.这样的分层开发有很多