Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Single instance apps and remoting

45 views
Skip to first unread message

davem

unread,
Nov 15, 2005, 1:21:02 PM11/15/05
to
Hi,

We've got a c# application that uses remoting, and everything was working.
We needed to make the client a single instance application, and to do we used
WindowsFormsApplicationBase, as described in the article
http://msdn.microsoft.com/msdnmag/issues/05/09/NETMatters/default.aspx

Internally WindowsFormsApplicationBase uses remoting to pass command line
args to the running local instance, using TcpChannel. Our code then started
RemotingException "The channel 'tcp' is already registered.".

I've named the new TcpChannel we're creating so the exception is no longer
thrown, but, when I try and use the proxy returned by Activator.GetObject I'm
getting a SocketException "An existing connection was forcibly closed by the
remote host". I also get the same error if I don't register an additional
TcpChannel. So, I'm guessing that Activator.GetObject is always using the
channel created by WindowsFormsApplicationBase (i think this is a secure
connection, hence the exception), and not the one we're creating.

If this is the case, how do I create the object using the right channel?
otherwise, what am I doing wrong?

I've tried to include some stripped down code below...

Thanks,


// The channel is registered on client as follows...
BinaryServerFormatterSinkProvider serverProv = new
BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

BinaryClientFormatterSinkProvider clientProv = new
BinaryClientFormatterSinkProvider();

IDictionary properties = new Hashtable();
properties["name"] = string.Empty;
TcpChannel channel = new TcpChannel(properties, clientProv, serverProv);

ChannelServices.RegisterChannel(channel, false);


// Proxy is created as follows...
string url = string.Format(CultureInfo.InvariantCulture, "tcp://{0}:{1}/TX",
Host, Port);
(ITX)Activator.GetObject(typeof(ITX), url);


// The channel is registered on server (where TXServer implements ITX)
TcpChannel channel = new TcpChannel(Port);
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
RemotingConfiguration.RegisterWellKnownServiceType(typeof(TXServer), "TX",
WellKnownObjectMode.Singleton);
ChannelServices.RegisterChannel(channel, false);

Grumpy1

unread,
Nov 23, 2005, 2:15:02 PM11/23/05
to
Have you founda solution to this problem yet. I'm having the same issue.

davem

unread,
Nov 25, 2005, 6:14:03 AM11/25/05
to
Hi,

The TcpChannel created internally is given the default priority. I create
our additional channel with a higher priority, which seems to solve the
problem. I'm not sure this is a proper fix, but it seems to work.


System.Collections.IDictionary properties = new
System.Collections.Hashtable();
properties["name"] = string.Empty;
properties["priority"] = "10";

channel = new TcpChannel(properties, clientProv, serverProv);

0 new messages