Krishna Kumar .P
7/1/2004 8:04:00 PM
Prabhu,
You have to register a channel as well in the client for the callback to
happen. Here is a sample
BinaryServerFormatterSinkProvider provider = new
BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 0;
TcpChannel tcpChannel = new TcpChannel(props, null,
provider);
ChannelServices.RegisterChannel(tcpChannel);
Callback needs to have channel. Port 0 is fine. Remoting will pickup the
available port for the callback to happen.
HTH,
-KRishna
"Prabhu Shastry" <google@gilpi.com> wrote in message
news:63fd70f.0407011106.7b69266f@posting.google.com...
>I am writing a sample app which uses Remoting and events (C#). I can
> instanciate the object and work with it, but when the remote object
> calls the event callback, I get an exception: "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."
>
> Here is the sample that I have (slightly modified from the sample in
> Professional C#).
>
> When RemoteObject calls the StatusEvent handler, I get the above
> exception. I have no idea what''s going wrong!
>
> NOTE: Just to make things easier, I have hard coded the server IP
> address as ''localhost''. All binaries reside on the same system and in
> same directory.
>
>
> Remote Object [.NET Class Library]
> ==================================
> using System;
> using System.Threading;
>
> namespace RemotingSample
> {
> public delegate void StatusEvent(object sender, StatusEventArgs e);
>
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> public class RemotingObject : MarshalByRefObject
> {
> public RemotingObject()
> {
> Console.WriteLine("RemotingObject");
> }
>
> public void LongWorking(int Sec)
> {
> Console.WriteLine("==>LongWorking for {0} seconds...", Sec);
> for(int i=0; i<Sec; i++)
> {
> Thread.Sleep(1000);
> if(Status != null)
> {
> Console.WriteLine("About to call Status Event handler...");
> Status(this, null);
> }
> }
> }
>
> public event StatusEvent Status;
> }
>
> [Serializable]
> public class StatusEventArgs
> {
> public StatusEventArgs(string msg)
> {
> message = msg;
> }
>
> public string Message
> {
> get
> {
> return message;
> }
> set
> {
> message = value;
> }
> }
>
> private string message;
> }
> }
>
>
> Remote Server [.NET Console App]
> ================================
> using System;
> using System.Runtime.Remoting;
> using System.Runtime.Remoting.Channels;
> using System.Runtime.Remoting.Channels.Tcp;
> using System.Data;
> using System.Configuration;
> using System.Runtime.Serialization.Formatters;
> using System.Collections;
> using RemotingSample;
>
> namespace RemotingSample
> {
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> class RemotingServer
> {
> private static uint m_port;
>
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main(string[] args)
> {
> System.Console.WriteLine("Launching Remoting Server...");
>
> m_port = uint.Parse(ConfigurationSettings.AppSettings["ServerPort"]);
> System.Console.WriteLine("Port = " + m_port);
>
> BinaryServerFormatterSinkProvider provider = new
> BinaryServerFormatterSinkProvider();
> provider.TypeFilterLevel = TypeFilterLevel.Full;
> IDictionary props = new Hashtable();
> props["port"] = m_port;
> TcpChannel chan1 = new TcpChannel(props, null, provider);
> ChannelServices.RegisterChannel(chan1);
>
> Console.WriteLine("Accepting calls to: {0}/RemotingObject",m_port);
> RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingObject),
> "RemotingObject", WellKnownObjectMode.Singleton);
>
> Console.WriteLine("Press any key to exit...");
> Console.ReadLine();
> }
> }
> }
>
>
> Remote Client [.NET Console App]
> ================================
> using System;
> using System.Runtime.Remoting;
> using System.Runtime.Remoting.Messaging;
> using System.Runtime.Remoting.Channels;
> using System.Runtime.Remoting.Channels.Tcp;
> using System.Configuration;
> using System.Threading;
> using System.ComponentModel;
> using System.Runtime.Serialization;
> using System.Diagnostics;
> using System.Runtime.Serialization.Formatters;
> using System.Collections;
> using RemotingSample;
>
> namespace RemotingSample
> {
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> class RemoteClient: MarshalByRefObject
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main(string[] args)
> {
> BinaryServerFormatterSinkProvider provider = new
> BinaryServerFormatterSinkProvider();
> provider.TypeFilterLevel = TypeFilterLevel.Full;
>
> TcpChannel chan = new TcpChannel(null, null, provider);
>
> bool RegisterChannel = true;
> for (int i=0;i < ChannelServices.RegisteredChannels.Length;i++)
> {
> if (ChannelServices.RegisteredChannels[i].ChannelName ==
> chan.ChannelName)
> {
> RegisterChannel = false;
> }
> }
> if (RegisterChannel)
> {
> Console.WriteLine("Registering Client channel");
> ChannelServices.RegisterChannel(chan);
> }
> else
> {
> Console.WriteLine("channel already registered..");
> }
>
> string szTypeString = "tcp://localhost:8085/RemotingObject";
>
> EventSink sink = new EventSink();
> RemotingObject obj = (RemotingObject)
> Activator.GetObject(typeof(RemotingObject), szTypeString);
> obj.Status += new StatusEvent(sink.StatusHandler);
> obj.LongWorking(5);
> obj.Status -= new StatusEvent(sink.StatusHandler);
> Console.WriteLine("Press any key to exit...");
> Console.ReadLine();
> }
> }
>
> class EventSink: MarshalByRefObject
> {
> public EventSink()
> {
>
> }
>
> [OneWay]
> public void StatusHandler(object sender, StatusEventArgs e)
> {
> Console.WriteLine("EventSink: Event occurred!");
> }
> }
> }