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.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();
//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();

浙公网安备 33010602011771号