Singleton object across processes.

  • Thread starter Thread starter Rob.J.White
  • Start date Start date
R

Rob.J.White

Hello,
I'm stuck, essentially I have a c# object that is visible to COM and
to other .net applications. The object in question provides
communications between machines for reporting an the like. Essentially
the problem is that because of a Socket.Bind() call I can only have one
instance of the object in existence on a PC at any given time. I'm
trying to find a way that I can allow both COM and .net clients access
to the same object, but from different processes.
I tried using a windows service, but that's no good as it won't
allow COM interoperability. I looked at object pooling, but I know
little to nothing about the subject and it didn't really seem to be
what I wanted.
Is there a way that I can have the object accessible to all clients? Or
am I essentially trying to do something impossible?
Thanks for any help.
Rob
 
Try using System.Runtime.Remoting.

Register a Channel using ChannelServices, then register a remotable Type (derives from MarshalByRefObject) using
RemotingConfiguration.

I suggest writing a managed library that the COM app can use to connect to the remoted object. In other words, register a managed
object for COM interop that can consume the remoted object and serve as the interface from the COM world to the .NET remoting world.
 
Interesting blog entry, but it seems the first paragraph may be a bit misleading...

..NET remoting does work with a Window's Service.
..NET remoting doesn't offer a secure channel, but does provide a sink chain that you can "plug" into to perform encryption and
decryption, using System.Security.Cryptography, on the raw network stream. There is an MSDN article that explains exactly how to do
this in the most basic fashion. See below for the link.
it seems like a lot of hops to make a local
method call.

I had assumed that you weren't making a local call since you were using a Socket as you mentioned in your original post. If it's a
local call, service and client code is executing in the same AppDomain, then you don't need remoting or DCOM.

Here are some links for Remoting in case you decide to go that route (watch for wrapping):

..NET Remoting:
http://msdn.microsoft.com/library/d...us/dndotnet/html/introremoting.asp?frame=true

Examples:
http://msdn.microsoft.com/library/d...ingexampleasynchronousremoting.asp?frame=true

Assymetric Encryption Channel Sink:
http://msdn.microsoft.com/msdnmag/issues/03/06/NETRemoting/


Hope it helps ;)
 
Back
Top