all groups > dotnet remoting > may 2006 >
You're in the

dotnet remoting

group:

Callbacks to client


Callbacks to client Casper Hornstrup
5/29/2006 6:02:55 PM
dotnet remoting:
I need to invoke a method on the client from the remote server object. How
do I do this? Of course you can do exactly the reverse of the client->server
scenario, but I thought .NET remoting was smarter than that. A simple
example would be nice if you have one. Now I've run into the exception
below. I've put some of the important code here.

Shared code:
public interface ISubscriber {

void ReceiveMessage(MobileNumber mobileNumber, Message message); }

public interface IService {

void Subscribe(ISubscriber subscriber);

void InjectMessage(MobileNumber mobileNumber, Message message); }


Server code:

public class Service : MarshalByRefObject, IService

{

private List<ISubscriber> subscribers = new List<ISubscriber>();

public void Subscribe(ISubscriber subscriber)

{

lock (typeof(Service))

{

subscribers.Add(subscriber);

}

}

private void NotifySubscribers(MobileNumber mobileNumber, Message message)

{

lock (typeof(Service))

{

foreach (ISubscriber subscriber in subscribers)

subscriber.ReceiveMessage(mobileNumber, message);

}

}

public void InjectMessage(MobileNumber mobileNumber, Message message)

{

// ...

}

}


Client code:

IService service = (IService)Activator.GetObject(typeof(IService), Url);

service.Subscribe(new Subscriber());



[Serializable]

public class Subscriber : MarshalByRefObject, ISubscriber

{

public void ReceiveMessage(MobileNumber mobileNumber, Message message)

{

Console.WriteLine("ReceiveMessage()");

}

}


System.Runtime.Remoting.RemotingException was unhandled by user code
Message="This remoting proxy has no channel sink which means either the
server has no registered server channels that are listening, or this
application has no suitable client channel to talk to the server."
Source="mscorlib"
StackTrace:
Server stack trace:
at
System.Runtime.Remoting.Proxies.RemotingProxy.InternalInvoke(IMethodCallMessage
reqMcmMsg, Boolean useDispatchMessage, Int32 callType)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage
reqMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)


Re: Callbacks to client Spam Catcher
5/31/2006 2:18:50 AM
"Casper Hornstrup" <ch@eudicon.com> wrote in
news:e$FRclzgGHA.3984@TK2MSFTNGP02.phx.gbl:

[quoted text, click to view]

Take a look at solution #2 (it works great):

http://www.codeproject.com/csharp/RemotingAndEvents.asp

Basically you pass a client reference to the server. The server does all
the event handling and "pushes" events to the client (by manually invoking
Re: Callbacks to client Casper Hornstrup
5/31/2006 10:15:51 PM

[quoted text, click to view]

Cool. I got it working. Didn't realize that I needed a 3rd party component
at first, but with that component it works.

Casper

Re: Callbacks to client Spam Catcher
6/1/2006 12:05:20 AM
"Casper Hornstrup" <ch@eudicon.com> wrote in
news:#8btP8OhGHA.4368@TK2MSFTNGP03.phx.gbl:

[quoted text, click to view]

Actually you don't need the 3rd party component (we do it with standard
remoting) but Geniune Channels adds a lot of extra features such as bi-
AddThis Social Bookmark Button