Chester West
7/27/2004 11:49:00 PM
Ok...It is brain surgery, although it shouldn't be....
I've got ONE application, to be used either as a client or as a server
I've got two EXACTLY the same objects, with events. The ONLY difference is
the name of the object.
I can get the application to register the object for usage (either in client
or server mode).
As soon as I attempt to get an instance for usage I get the following error
message::
"The channel tcp is already registered"
The code for registering the objects, as well as the code for intializing
the objects for calling methods, etc.
are below:
The routines returning the SAME error message are:
GetClientForRemotingUsage()
GetServerForRemotingUsage()
The URI's being used are:
tcp://10.0.1.205:8087/VMClient
tcp://10.0.1.204:8086/VMServer
PLEASE HELP.........Otherwise I'll have to implement remoting using SQL
Server polling which will not scale......
Thanks
Chester West
public TcpServerChannel RemoteChannelServer=null;
public TcpServerChannel RemoteChannelClient=null;
public int PortOfServer=8086;
public int PortOfClient=8087;
//The following object will handle events on the agent side that are
triggered by the client
public LOVE4000.AgentRemoteControl AgentServer=null;
//The following object will handle events on the client side triggered by
the agent
public LOVE4000.ClientRemoteControl ClientServer=null;
//The following make the remoting object available to be consumed....
public bool RegisterClientAsServer()
{
bool ReturnValue=true;
try
{
this.ClientServer=new ClientRemoteControl();
string url =
"tcp://"+this.IPAddress+":"+this.PortOfClient.ToString()+"/VMClient";
MessageBox.Show("Registering CLIENT for remote usage\n"+url);
this.RemoteChannelClient=new TcpServerChannel(this.PortOfClient);
ChannelServices.RegisterChannel(this.RemoteChannelClient);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClientRemoteContro
l),"VMClient",WellKnownObjectMode.Singleton);
System.Runtime.Remoting.RemotingServices.Marshal(this.ClientServer,"VMClient
",typeof(ClientRemoteControl));
}
catch (System.Exception ex)
{
MessageBox.Show("Client machine FAILED to register as SERVER for
Agent\n"+ex.Message+"\nSource:"+ex.Source);
ReturnValue=false;
}
return ReturnValue;
}
public bool RegisterServerAsServer()
{
bool ReturnValue=true;
try
{
this.AgentServer=new AgentRemoteControl();
string url =
"tcp://"+this.IPAddress+":"+this.PortOfServer.ToString()+"/VMServer";
MessageBox.Show("Registering Server for remote usage\n"+url);
this.RemoteChannelServer=new TcpServerChannel(this.PortOfServer);
ChannelServices.RegisterChannel(this.RemoteChannelServer);
RemotingConfiguration.RegisterWellKnownServiceType(typeof
(AgentRemoteControl) , "VMServer", WellKnownObjectMode.Singleton ) ;
System.Runtime.Remoting.RemotingServices.Marshal(this.AgentServer,"VMServer"
,typeof(AgentRemoteControl));
}
catch (System.Exception ex)
{
MessageBox.Show("Agent machine FAILED to register as SERVER for
Client\n"+ex.Message+"\nSource:"+ex.Source);
ReturnValue=false;
}
return ReturnValue;
}
//
//The following allow a remoting object to be consumed...
//They are used when a connection is being made...
//
public bool GetClientForRemotingUsage()
{
//
//This gets a reference of the clients remoting object for the Agent machine
//
bool ReturnValue=true;
try
{
string url =
"tcp://"+this.ClientIP+":"+this.PortOfClient.ToString()+"/VMClient" ;
MessageBox.Show("Attempting to reference for AGENT from CLIENT using the
following URI\n"+url);
RemotingConfiguration.RegisterWellKnownClientType (
typeof(ClientRemoteControl), url ) ;
TcpClientChannel channel = new TcpClientChannel( ) ;
ChannelServices.RegisterChannel(channel);
//Get the remoting object
this.ClientServer=new ClientRemoteControl();
}
catch (System.Exception ex)
{
MessageBox.Show("Agent machine FAILED to get Client Server Remoting object
reference\n"+ex.Message+"\nSource:"+ex.Source);
ReturnValue=false;
}
return ReturnValue;
}
public bool GetServerForRemotingUsage()
{
bool ReturnValue=true;
//This allows the agent to use an object on the clients machine
try
{
string url =
"tcp://"+this.ClientIP+":"+this.PortOfServer.ToString()+"/VMServer" ;
MessageBox.Show("Attempting to reference for CLIENT from AGENT using the
following URI\n"+url);
RemotingConfiguration.RegisterWellKnownClientType ( typeof (
AgentRemoteControl ), url ) ;
TcpClientChannel channel = new TcpClientChannel( ) ;
ChannelServices.RegisterChannel ( channel ) ;
//Get the remoting object
this.AgentServer=new AgentRemoteControl();
}
catch (System.Exception ex)
{
MessageBox.Show("Agent machine FAILED to register as SERVER for
Client\n"+ex.Message+"\nSource:"+ex.Source);
ReturnValue=false;
}
return ReturnValue;
}