凯锐

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  96 随笔 :: 39 文章 :: 212 评论 :: 23 引用
昨天的那篇隨筆﹐全部是使用配置文件來實現的。那么根據配置文件﹐如何生成代碼訪問模式?
1﹑首先將RemoteServer  和RemoteClient中的App.Config文件移除專案﹐注意是移除﹐不是刪除﹐要不﹐你以后要想再使用配置文件話﹐直接包含進來就可以啦。
2﹑在frmServer的建構改為﹕
        public frmServer()
        {
            InitializeComponent();

            
//使用配置文件
            
//RemotingConfiguration.Configure("RemoteServer.exe.config", false);

            
//使用代碼
            RemotingConfiguration.RegisterWellKnownServiceType(
                
typeof(RemoteObject.RemoteObject), 
                
"RemoteObject.RemoteObject"
                WellKnownObjectMode.Singleton);

            IChannel icTcp 
= new TcpChannel(8080);
            ChannelServices.RegisterChannel(icTcp, 
false);
        }
3﹑在frmClient中的Load事件的方法改為﹕
        private void frmClient_Load(object sender, EventArgs e)
        {
            
//Listen the Client request,config the client infomation
            
//RemotingConfiguration.Configure("RemoteClient.exe.config", false);
            RemoteObject.RemoteObject obj = (RemoteObject.RemoteObject)Activator.GetObject(typeof(RemoteObject.RemoteObject),
                
"tcp://localhost:8080/RemoteObject");
        }
余皆不變前一篇﹐運行測試就OK了。

posted on 2006-09-27 16:50 凯锐 阅读(265) 评论(0)  编辑 收藏 所属分类: .Net Remoting

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      

相关链接: