[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.remoting

Are callbacks supported - How do I subscribe to an event within a remote object from the CLIENT side

Chester West

7/29/2004 6:03:00 PM

After MANY hours of frustration, I've finally gotten an object to create...

However, I am attempting to get a callback by using delegates at both the
server and client.
The server and the client are one in the same application, just run on
different machines.

I've learned the hard way, that you can have as many remote objects as you
want in .NET
....you just need to remember that you can call ONE and only ONE of them if
you want things
to work.

Why? Because .NET is smart enough to be able to take two unique URI strings
and then, based on the 1st few characters, insure that they are to be
treated as being the same object
when registering the object. This insures that when registration occurs,
..NET will trigger an exception
due to the duplicate name.

Sunny has suggested having a Event Wrapper Class, which is fine except that
that would violate
the rule above, since I would need to send both the class I have now and the
wrapper....

Due to the rule above, I've combined the functionality of the client and the
server into one object.

Basically I follow a scheme of setting a property, which then performs a
callback using a delegate.

I'm having trouble registering the routine that will be called. The syntax
on the "CLIENT" side of
things is using the following syntax:
this.RemoteObject.ExecCmdByClient+=new ProcessIt(ClientServer_ExecCmd);


CAN SOMEONE PLEASE TELL ME EXACTLY IN CODE HOW TO ACCOMPLISH THIS??

WHAT WOULD THE CODE NEED TO LOOK LIKE ON THE CLIENT SIDE OF THINGS
TO REGISTER A CALLBACK???

I'm assuming it can be done...


The complete object is:
public delegate void ProcessIt();

public delegate void SendMsgToServer(string Message);

[Serializable]

public class AgentRemoteControl:MarshalByRefObject

{

private bool NeedAgentProcessing=false;

private bool NeedClientProcessing=false;



private bool ProcessCompleteByAgent=false;

private bool ProcessCompleteByClient=false;

private bool IsConnected=false;

private string MsgSent="";

private string TypeOfForm="";

private object frmRef;

//

//The following will be called to process a command

//on the agent side

//

public event ProcessIt ExecCmdByAgent;

//

//The following will be called to process a command

//on the client side

//

public event ProcessIt ExecCmdByClient;

//

//The following will signal an agent that the status

//of the client connection has changed

//

public event ProcessIt SignalAgentConnection;

//

//The following will signal a client that the status

//of the Agent connection has changed

//

public event ProcessIt SignalClientConnection;

//

//The Following will signal a client that the agent

//has completed the command desired

//

public event ProcessIt SignalAgentCmdCompletion;

//

//The following will signal a Agent that the client

//has completed the command desired

//

public event ProcessIt SignalClientCmdCompletion;

//

//The following will be called when a agent is sent

//a message by the client

//

public event SendMsgToServer SendAgentAMessage;

//

//The following will be called when a clent is sent

//a message by the agent

//

public event SendMsgToServer SendClientAMessage;



public string CmdToDo="";

public object Parm1;

public object Parm2;

public string MessageToShowAgent

{

get {return this.MsgSent;}

set

{

this.MsgSent=value;

if (this.SendAgentAMessage!=null)

{

this.SendAgentAMessage(this.MsgSent);

}

}

}

public string MessageToShowClient

{

get {return this.MsgSent;}

set

{

this.MsgSent=value;

if (this.SendClientAMessage!=null)

{

this.SendClientAMessage(this.MsgSent);

}

}

}



public void ClearClientEventHandlers()

{

this.ExecCmdByAgent=null;

this.SignalAgentCmdCompletion=null;

this.SignalClientConnection=null;

this.SendClientAMessage=null;

}





public bool ProcessingNeededByAgent

{

get {return NeedAgentProcessing;}

set

{

this.NeedAgentProcessing=value;

if (this.NeedAgentProcessing==true)

{

if (ExecCmdByAgent!=null)

{

this.ExecCmdByAgent();

}

}

}

}

public bool ProcessingNeededByClient

{

get {return NeedClientProcessing;}

set

{

this.NeedClientProcessing=value;

if (this.NeedClientProcessing==true)

{

if (ExecCmdByClient!=null)

{

this.ExecCmdByClient();

}

}

}

}

public bool WasProcessedByAgent

{

get {return this.ProcessCompleteByAgent;}

set

{

this.ProcessCompleteByAgent=value;

if (this.ProcessCompleteByAgent==true)

{

this.ProcessCompleteByAgent=false;

if (this.SignalAgentCmdCompletion!=null)

{

this.SignalAgentCmdCompletion();

}

}

}

}

public bool WasProcessedByClient

{

get {return this.ProcessCompleteByClient;}

set

{

this.ProcessCompleteByClient=value;

if (this.ProcessCompleteByClient==true)

{

this.ProcessCompleteByClient=false;

if (this.SignalClientCmdCompletion!=null)

{

this.SignalClientCmdCompletion();

}

}

}

}

public bool AgentHasClientConnection

{

get {return this.IsConnected;}

set

{

this.IsConnected=value;

if (this.IsConnected==true)

{

if (this.SignalAgentConnection!=null)

{

this.SignalAgentConnection();

}

}

}

}

public bool ClientHasAgentConnection

{

get {return this.IsConnected;}

set

{

this.IsConnected=value;

if (this.IsConnected==true)

{

if (this.SignalClientConnection!=null)

{

this.SignalClientConnection();

}

}

}

}


1 Answer

Ken Kolda

7/30/2004 8:51:00 PM

0

See comments inline below...

> I've learned the hard way, that you can have as many remote objects as you
> want in .NET
> ...you just need to remember that you can call ONE and only ONE of them if
> you want things
> to work.

This is certainly not true -- I think you'll find lots of people on this
newsgroup who have apps that remote many objects concurrently (or interact
with many remoted objects) without any problems.

>
> Why? Because .NET is smart enough to be able to take two unique URI
strings
> and then, based on the 1st few characters, insure that they are to be
> treated as being the same object
> when registering the object. This insures that when registration occurs,
> .NET will trigger an exception
> due to the duplicate name.

Can you show a very brief code example that causes this exception? What
you're saying above doesn't make any sense to me -- are you sure your code
isn't calling the same registration function twice with the same object
and/or URI?

>
> Sunny has suggested having a Event Wrapper Class, which is fine except
that
> that would violate
> the rule above, since I would need to send both the class I have now and
the
> wrapper....
>
> Due to the rule above, I've combined the functionality of the client and
the
> server into one object.
>
> Basically I follow a scheme of setting a property, which then performs a
> callback using a delegate.
>
> I'm having trouble registering the routine that will be called. The
syntax
> on the "CLIENT" side of
> things is using the following syntax:
> this.RemoteObject.ExecCmdByClient+=new ProcessIt(ClientServer_ExecCmd);
>

You should use normal syntax for hooking up the event, just as you've done.
When you say "I'm having trouble", can you be more specific? Do you get a
compile error, runtime error, it just doesn't work, ...

Ken