2013-11-28 43 views
0

当由如何在服务器中获取对象的引用?

RemotingConfiguration.RegisterWellKnownServiceType(typeof(Interfaces.client), Singleton", WellKnownObjectMode.Singleton); //in the server 

登记在服务器中的对象,然后通过

Interfaces.client mgr = (Interfaces.client)(Activator.GetObject(typeof(Interfaces.client), "tcp://localhost:1234/Singleton")); //in the client 

检索它在客户端,使得对象可以从客户端访问,我们可以看到在服务器端的修改,这已经完成了。 我的具体问题是:在服务器创建后,哪里可以找到对象的引用?如果是单播模式,我知道会有几个实例,尽管我假设实例是通过一些命名服务宏观存储的,或者直接存储在内存中的某个列表中。 请原谅我弱英语

回答

1

您将需要单独创建对象,然后封送它,而不是使用RegisterWellKnownServiceType:

Foo foo = new Foo();

RemotingServices.Marshal(foo, "Singleton");

所以客户端的更改将在服务器端反映在foo对象中。

+0

这样,就不可能在singlelecall模式下注册对象(每次调用一个实例) –

+0

@initParam这是正确的,它仅适用于单例模式。单个呼叫实例的生存时间应尽可能短。如果你需要访问单个调用实例服务器端,那么你的设计是错误的。 –

相关问题