草原上的野狼

啸苍天,没日月,孤单影只; 忍地寒,耐绝境,经熔炼,将成大业!

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

Window service 端

protected override void DoSetup()
        {
            DbXmlService.Home 
= this.home;
            DbXmlService.DbName 
= this.dbName;
            DbXmlService.ContainerNames 
= new string[]{
                                                          newsImageSummaryContainer,
                                                          newsXmlSummaryContainer,
                                                          newsXmlHistorySummaryContainer,
                                                          newsXslSummaryContainer
                                                      };
            
            BinaryServerFormatterSinkProvider serverSinkProvider 
= new BinaryServerFormatterSinkProvider();
            serverSinkProvider.TypeFilterLevel 
= System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            
            IDictionary properties 
= new Hashtable();
            properties[
"name"= "tcp8085";
            properties[
"port"= 8085;

            TcpServerChannel channel 
= new TcpServerChannel(properties,    serverSinkProvider);
            ChannelServices.RegisterChannel(channel);

            RemotingConfiguration.RegisterWellKnownServiceType(
typeof(DbXmlService), "DbXmlService", WellKnownObjectMode.Singleton);
        }

只要在DbXmlService里面初始化Berkeley Db 和Berkeley Db Xml,然后返回DbXmlManager.

Client 端

BinaryClientFormatterSinkProvider clientSinkProvider = new BinaryClientFormatterSinkProvider();
                        
//clientSinkProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                        IDictionary properties 
= new Hashtable();
                        properties[
"name"= "tcp8085";
                        properties["port"= 8085;
            
                        TcpClientChannel channel 
= new TcpClientChannel(properties, clientSinkProvider);
                        
                        
foreach (IChannel ch in ChannelServices.RegisteredChannels) {
                            
if ( ch.ChannelName == channel.ChannelName ) {
                                regChanFlag 
= true;
                                
break;
                            }
                        }
                        
if(regChanFlag == false) {
                            ChannelServices.RegisterChannel(channel);
                        }
                        DbXmlService dbXmlService 
= (DbXmlService)Activator.GetObject(typeof(DbXmlService),"tcp://localhost:8085/DbXmlService");
                        
if (dbXmlService == null) {
                            log.Error(
"False to link service .");
                            
return;
                        }
                        dbXmlManager 
= dbXmlService.GetDbXmlManager();



posted on 2007-10-18 19:16  血狼  阅读(287)  评论(0)    收藏  举报