Sunny
6/10/2004 5:29:00 PM
Hi Stephan,
you do not need to implement the singleton pattern to get what you want.
Change your code as follows:
public sealed class Singleton: MarshalByReferenceObject,
IRemoteInterfaceDefinition
> {
> private string message;
//default constructor will be provided by the compiler
>
> public string Message
> {
> set
> {
> message = value;
> }
> }
> //IRemoteInterfaceDefinition members
> public string getMessage()
> {
> return message;
> }
> }
>
Then instaniate and expose your object to remoting as follows:
//register here the channel, but not the object
Singleton myremobj = new Singleton();
RemotingServices.Marshal(myremobg, "<myuri>", typeof
(IRemoteInterfaceDefinition));
Now at the server you have access to the object thru myremoobj, so you
can set the Message property.
And the clients will access that same instance.
You have to consider that every remoting call is made on a different
thread, so your class have to implement some thread safety.
Also, you have to manage its lifetime as well. Otherwise even you still
have a reference to the object in your server and it is not garbage
collected, when its lifetime expires, it will be disconnected from the
remoting infrastructure and will not be accessible from the client.
Hope that helps
Sunny