About the remoting event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?ZmFpcnl2b2ljZQ==?=

    About the remoting event

    in a remoting application, i set a event in the host, and let the client to
    book it, and in the host side i set the TypeFilterLevel to Full and open the
    callback port in the client side, but told that these was an exception on the
    invoked object.
    can anyone tell my why? It is a very simple application just to test, and
    here is the code, i am using vs2008, thanx in advaned.

    ----------server side----------------------
    using System.Collecti ons.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime. Remoting;
    using System.Runtime. Remoting.Channe ls;
    using System.Runtime. Remoting.Channe ls.Ipc;
    using System.Runtime. Remoting.Channe ls.Tcp;
    using System.Runtime. Serialization.F ormatters;
    using System.IO;
    using System.Collecti ons;

    namespace RcServer
    {
    class Program
    {
    static void Main(string[] args)
    {
    IDictionary pros = new Hashtable();
    pros["portName"] = "host";
    BinaryServerFor matterSinkProvi der ss = new
    BinaryServerFor matterSinkProvi der();
    ss.TypeFilterLe vel = TypeFilterLevel .Full;
    IChannel cnl = new IpcChannel(pros , new
    BinaryClientFor matterSinkProvi der(), ss);

    ChannelServices .RegisterChanne l(cnl, false);
    RemotingConfigu ration.Register WellKnownServic eType(typeof(Ca t),
    "cat", WellKnownObject Mode.Singleton) ;
    Cat cat = new Cat();
    Console.WriteLi ne("go");
    Console.ReadLin e();
    }
    }


    public class Cat : MarshalByRefObj ect
    {
    public event EventHandler OnScreaming;
    public void Scream()
    {
    Console.WriteLi ne("i am wake");
    if (this.OnScreami ng != null)
    this.OnScreamin g(this,null);
    }

    }
    }

    ----------------client side-------------------------
    using System;
    using System.Collecti ons.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime. Remoting;
    using System.Runtime. Remoting.Channe ls;
    using System.Runtime. Remoting.Channe ls.Ipc;
    using System.Runtime. Serialization.F ormatters;
    using System.Collecti ons;
    using RcServer;

    namespace RcClient
    {
    class Program
    {
    static void Main(string[] args)
    {
    IChannel cnl = new IpcChannel("MyC allback");
    ChannelServices .RegisterChanne l(cnl, false);
    RemotingConfigu ration.Register WellKnownClient Type(typeof(Cat ),
    @"ipc://host/cat");
    Cat c = (Cat)Activator. CreateInstance( typeof(Cat));
    Rat jy = new Rat();
    jy.ThereIsaCat( c);
    c.Scream();

    }
    }

    [Serializable]
    public class Rat:MarshalByRe fObject
    {
    public void ThereIsaCat(Cat cat)
    {
    cat.OnScreaming += new EventHandler(th is.cat_OnScream ing);
    }


    void cat_OnScreaming (object sender, EventArgs e)
    {
    Console.WriteLi ne("cat's awake, run quick!");
    }
    }
    }

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: About the remoting event

    I find that using events is a PITA when using remoting. Rather, I would
    define a callback interface that the client implements, and then make sure
    that the class that implements it derives from MarshalByRefObj ect, and send
    that to the server to call back onto when you want to fire an event. It's
    much cleaner, and it works.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "fairyvoice " <fairyvoice@dis cussions.micros oft.comwrote in message
    news:4604E3F5-AF6B-4DDD-9C50-4FCBBD4EBB1F@mi crosoft.com...
    in a remoting application, i set a event in the host, and let the client
    to
    book it, and in the host side i set the TypeFilterLevel to Full and open
    the
    callback port in the client side, but told that these was an exception on
    the
    invoked object.
    can anyone tell my why? It is a very simple application just to test, and
    here is the code, i am using vs2008, thanx in advaned.
    >
    ----------server side----------------------
    using System.Collecti ons.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime. Remoting;
    using System.Runtime. Remoting.Channe ls;
    using System.Runtime. Remoting.Channe ls.Ipc;
    using System.Runtime. Remoting.Channe ls.Tcp;
    using System.Runtime. Serialization.F ormatters;
    using System.IO;
    using System.Collecti ons;
    >
    namespace RcServer
    {
    class Program
    {
    static void Main(string[] args)
    {
    IDictionary pros = new Hashtable();
    pros["portName"] = "host";
    BinaryServerFor matterSinkProvi der ss = new
    BinaryServerFor matterSinkProvi der();
    ss.TypeFilterLe vel = TypeFilterLevel .Full;
    IChannel cnl = new IpcChannel(pros , new
    BinaryClientFor matterSinkProvi der(), ss);
    >
    ChannelServices .RegisterChanne l(cnl, false);
    RemotingConfigu ration.Register WellKnownServic eType(typeof(Ca t),
    "cat", WellKnownObject Mode.Singleton) ;
    Cat cat = new Cat();
    Console.WriteLi ne("go");
    Console.ReadLin e();
    }
    }
    >
    >
    public class Cat : MarshalByRefObj ect
    {
    public event EventHandler OnScreaming;
    public void Scream()
    {
    Console.WriteLi ne("i am wake");
    if (this.OnScreami ng != null)
    this.OnScreamin g(this,null);
    }
    >
    }
    }
    >
    ----------------client side-------------------------
    using System;
    using System.Collecti ons.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime. Remoting;
    using System.Runtime. Remoting.Channe ls;
    using System.Runtime. Remoting.Channe ls.Ipc;
    using System.Runtime. Serialization.F ormatters;
    using System.Collecti ons;
    using RcServer;
    >
    namespace RcClient
    {
    class Program
    {
    static void Main(string[] args)
    {
    IChannel cnl = new IpcChannel("MyC allback");
    ChannelServices .RegisterChanne l(cnl, false);
    RemotingConfigu ration.Register WellKnownClient Type(typeof(Cat ),
    @"ipc://host/cat");
    Cat c = (Cat)Activator. CreateInstance( typeof(Cat));
    Rat jy = new Rat();
    jy.ThereIsaCat( c);
    c.Scream();
    >
    }
    }
    >
    [Serializable]
    public class Rat:MarshalByRe fObject
    {
    public void ThereIsaCat(Cat cat)
    {
    cat.OnScreaming += new EventHandler(th is.cat_OnScream ing);
    }
    >
    >
    void cat_OnScreaming (object sender, EventArgs e)
    {
    Console.WriteLi ne("cat's awake, run quick!");
    }
    }
    }
    >

    Comment

    • =?Utf-8?B?ZmFpcnl2b2ljZQ==?=

      #3
      Re: About the remoting event

      thanks Nicholas, when you said "callback interface" did you mean the one in
      the asynchronous model, i am not very clear.
      May you tell me more precisely or show me a few codes? thanx

      "Nicholas Paldino [.NET/C# MVP]" wrote:
      I find that using events is a PITA when using remoting. Rather, I would
      define a callback interface that the client implements, and then make sure
      that the class that implements it derives from MarshalByRefObj ect, and send
      that to the server to call back onto when you want to fire an event. It's
      much cleaner, and it works.
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "fairyvoice " <fairyvoice@dis cussions.micros oft.comwrote in message
      news:4604E3F5-AF6B-4DDD-9C50-4FCBBD4EBB1F@mi crosoft.com...
      in a remoting application, i set a event in the host, and let the client
      to
      book it, and in the host side i set the TypeFilterLevel to Full and open
      the
      callback port in the client side, but told that these was an exception on
      the
      invoked object.
      can anyone tell my why? It is a very simple application just to test, and
      here is the code, i am using vs2008, thanx in advaned.

      ----------server side----------------------
      using System.Collecti ons.Generic;
      using System.Linq;
      using System.Text;
      using System.Runtime. Remoting;
      using System.Runtime. Remoting.Channe ls;
      using System.Runtime. Remoting.Channe ls.Ipc;
      using System.Runtime. Remoting.Channe ls.Tcp;
      using System.Runtime. Serialization.F ormatters;
      using System.IO;
      using System.Collecti ons;

      namespace RcServer
      {
      class Program
      {
      static void Main(string[] args)
      {
      IDictionary pros = new Hashtable();
      pros["portName"] = "host";
      BinaryServerFor matterSinkProvi der ss = new
      BinaryServerFor matterSinkProvi der();
      ss.TypeFilterLe vel = TypeFilterLevel .Full;
      IChannel cnl = new IpcChannel(pros , new
      BinaryClientFor matterSinkProvi der(), ss);

      ChannelServices .RegisterChanne l(cnl, false);
      RemotingConfigu ration.Register WellKnownServic eType(typeof(Ca t),
      "cat", WellKnownObject Mode.Singleton) ;
      Cat cat = new Cat();
      Console.WriteLi ne("go");
      Console.ReadLin e();
      }
      }


      public class Cat : MarshalByRefObj ect
      {
      public event EventHandler OnScreaming;
      public void Scream()
      {
      Console.WriteLi ne("i am wake");
      if (this.OnScreami ng != null)
      this.OnScreamin g(this,null);
      }

      }
      }

      ----------------client side-------------------------
      using System;
      using System.Collecti ons.Generic;
      using System.Linq;
      using System.Text;
      using System.Runtime. Remoting;
      using System.Runtime. Remoting.Channe ls;
      using System.Runtime. Remoting.Channe ls.Ipc;
      using System.Runtime. Serialization.F ormatters;
      using System.Collecti ons;
      using RcServer;

      namespace RcClient
      {
      class Program
      {
      static void Main(string[] args)
      {
      IChannel cnl = new IpcChannel("MyC allback");
      ChannelServices .RegisterChanne l(cnl, false);
      RemotingConfigu ration.Register WellKnownClient Type(typeof(Cat ),
      @"ipc://host/cat");
      Cat c = (Cat)Activator. CreateInstance( typeof(Cat));
      Rat jy = new Rat();
      jy.ThereIsaCat( c);
      c.Scream();

      }
      }

      [Serializable]
      public class Rat:MarshalByRe fObject
      {
      public void ThereIsaCat(Cat cat)
      {
      cat.OnScreaming += new EventHandler(th is.cat_OnScream ing);
      }


      void cat_OnScreaming (object sender, EventArgs e)
      {
      Console.WriteLi ne("cat's awake, run quick!");
      }
      }
      }
      >
      >
      >

      Comment

      Working...