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)