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!");
}
}
}
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