我想知道是否可以在远程服务器上向特定频道注册一个众所周知的服务,而不是在所有可用频道上注册。
我的代码如下:
我在远程处理服务器上使用以下代码
创建了2个单独的tcpchannelIDictionary rcProperties1 = new Hashtable();
rcProperties1["port"] = "1688";
rcProperties1["name"] = "tcp1";
TcpChannel tcp1 = new TcpChannel(rcProperties1, null, null);
IDictionary rcProperties2 = new Hashtable();
rcProperties2["port"] = "1689";
rcProperties2["name"] = "tcp2";
TcpChannel tcp2 = new TcpChannel(rcProperties2, null, null);
//--------------------------------------------------
// Register tcp channels
//--------------------------------------------------
ChannelServices.RegisterChannel(tcp1, false);
ChannelServices.RegisterChannel(tcp2, false);
然后我使用以下
托管了2个远程对象Type rt = typeof(wxMessage);
RemotingConfiguration.RegisterWellKnownServiceType(
rt, "Classes/wxMessage.rem", WellKnownObjectMode.Singleton);
rt = typeof(wxType);
RemotingConfiguration.RegisterWellKnownServiceType(
rt, "Classes/wxType.rem", WellKnownObjectMode.Singleton);
在客户端上,我通过Activator.GetObject(...)
调用远程对象string uri = "tcp://localhost:1688/";
IConcrete1 objMessageRemote = (IConcrete1)Activator.GetObject(
typeMessageLocal, uri + "Classes/wxMessage.rem");
IConcrete2 objTypeRemote = (IConcrete2)Activator.GetObject(
typeTypeLocal, uri + "Classes/wxType.rem");
问题是,如果我将uri端口设置为1688或1689并不重要,我仍然可以检索远程对象。
我想要做的是让服务器在一个通道上托管某个对象,在另一个通道上托管另一个对象。可以这样做吗?