Unregister Server Activated Object ?
-
I use remoting in my application, which proofed to be very useful but now i have a small problem. In the server application the remote object is register as an available service in singleton mode. RemotingConfiguration.RegisterWellKnownServiceType( typeof(RemoteObject), "Server", WellKnownObjectMode.Singleton ); Now I'm searching a way to unregister it in the server application, so no remote calls from clients are processed?
-
I use remoting in my application, which proofed to be very useful but now i have a small problem. In the server application the remote object is register as an available service in singleton mode. RemotingConfiguration.RegisterWellKnownServiceType( typeof(RemoteObject), "Server", WellKnownObjectMode.Singleton ); Now I'm searching a way to unregister it in the server application, so no remote calls from clients are processed?
If you use a configuration file to publish the types you want remoted, you can use the
RemotingServices.Disconnect
to stop the object from receiving further messages. See the documentation for that method for more information. The only other way is to stop theAppDomain
in which the WKO is registered. If you're using a Windows Service, you can stop the service both manually using the Services snap-in or theServiceController
class. If you're hosting this in another process, you could create a separateAppDomain
and launch an executable that registers the WKO, then when you want to stop it unload theAppDomain
usingAppDomain.Unload
. One more way that wouldn't unregister the WKO but would keep it from processing requests (which I wouldn't recommend because clients will still see the published WKO) would be to put the interface in a shared library and the implementation of that on the server. Have an internal method that you can call that could do something like set a flag. In each of your interface implementation methods / properties, check that flag and either don't return anything or throw some sort of exception, likeNotSupportedException
or something. The first two methods are more complete, IMO.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
If you use a configuration file to publish the types you want remoted, you can use the
RemotingServices.Disconnect
to stop the object from receiving further messages. See the documentation for that method for more information. The only other way is to stop theAppDomain
in which the WKO is registered. If you're using a Windows Service, you can stop the service both manually using the Services snap-in or theServiceController
class. If you're hosting this in another process, you could create a separateAppDomain
and launch an executable that registers the WKO, then when you want to stop it unload theAppDomain
usingAppDomain.Unload
. One more way that wouldn't unregister the WKO but would keep it from processing requests (which I wouldn't recommend because clients will still see the published WKO) would be to put the interface in a shared library and the implementation of that on the server. Have an internal method that you can call that could do something like set a flag. In each of your interface implementation methods / properties, check that flag and either don't return anything or throw some sort of exception, likeNotSupportedException
or something. The first two methods are more complete, IMO.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Thanks for info! I'm now using this code in my server application and it functions very well. this.remoteObject = new RemoteObject(); System.Runtime.Remoting.RemotingServices.Marshal(this.remoteObject, "Server"); System.Runtime.Remoting.RemotingServices.Disconnect(this.remoteObject);