ServicesResourcesConferences Our TeamWeblogsAboutContact
     
  

Developer Resources

  Architecture Briefings
  Articles
  Conversations
  Tools and Samples
  Books

HOWTO: Access the same type from multiple servers

Question

Why can't I use RemotingConfiguration.RegisterActivatedClientType() more than once in the same program? I am trying to activate the same server-type from more than one server with a single client.

I have something like this:

for (i=0; i<servernames.Count; i++)
{
   string Url = "tcp:\\" + servernames[i] + ":8085\ServerUri";
   RemotingConfiguration.RegisterActivatedClientType(ServerType, Url);
   server[i] = new ServerType();
}

Only the first pass through this loop works. When (i == 1), I get the following exception:

Error: Attempt to redirect activation of type 'ApplicationName, ServerType' which is already redirected.

What is the workaround here?

Answer

The only workaround I see here is to use a statement like the following:

for (i=0; i<servernames.Count; i++)
{
   string Url = "tcp:\\" + servernames[i] + ":8085\ServerUri";
   System.Runtime.Remoting.Activation.UrlAttribute urlattr = 
           new System.Runtime.Remoting.Activation.UrlAttribute (Url);

   object[] act = {urlattr};
   server[i] = (ServerType)
   Activator.CreateInstance(typeof(ServerType),null,act);
}

i.e. you have to use explicit object creation instead of registered types.






 

© 2002-2006 by Thinktecture, Ingo Rammer and Christian Weyer. All rights reserved. | Contact | Impressum