[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

One more try before I give up on .NET Remoting

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;

}



1 Answer

Sam Santiago

7/28/2004 1:19:00 AM

0

You have to specify a channel name either in your config file or
programmatically depending on how you are configuring remoting in your
application when you define more than one channel. If you are using
configuration files then change or add the id attribute for the channel
element in your config file; here's an example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gnconchannelte...

Check out this link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRuntimeRemotingChannelsChannelServicesClassRegisterChannelTopic.asp?...

Here's an excerpt:
Note You cannot register two channels with the same name in an
AppDomain. By default, the name of an HttpChannel is "http", and the name of
a TcpChannel is "tcp". Therefore, if you want to register two channels of
the same type, you must specify a different name for one of them through
configuration properties.
Thanks,

Sam
--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTe...
_______________________________
"Chester West" <cwest@video-mation.com> wrote in message
news:OOB3wQDdEHA.3896@TK2MSFTNGP10.phx.gbl...
> 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;
>
> }
>
>
>