About the remoting event
- From: fairyvoice <fairyvoice@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 1 Jul 2008 04:39:00 -0700
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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Serialization.Formatters;
using System.IO;
using System.Collections;
namespace RcServer
{
class Program
{
static void Main(string[] args)
{
IDictionary pros = new Hashtable();
pros["portName"] = "host";
BinaryServerFormatterSinkProvider ss = new
BinaryServerFormatterSinkProvider();
ss.TypeFilterLevel = TypeFilterLevel.Full;
IChannel cnl = new IpcChannel(pros, new
BinaryClientFormatterSinkProvider(), ss);
ChannelServices.RegisterChannel(cnl, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Cat),
"cat", WellKnownObjectMode.Singleton);
Cat cat = new Cat();
Console.WriteLine("go");
Console.ReadLine();
}
}
public class Cat : MarshalByRefObject
{
public event EventHandler OnScreaming;
public void Scream()
{
Console.WriteLine("i am wake");
if (this.OnScreaming != null)
this.OnScreaming(this,null);
}
}
}
----------------client side-------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Serialization.Formatters;
using System.Collections;
using RcServer;
namespace RcClient
{
class Program
{
static void Main(string[] args)
{
IChannel cnl = new IpcChannel("MyCallback");
ChannelServices.RegisterChannel(cnl, false);
RemotingConfiguration.RegisterWellKnownClientType(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:MarshalByRefObject
{
public void ThereIsaCat(Cat cat)
{
cat.OnScreaming += new EventHandler(this.cat_OnScreaming);
}
void cat_OnScreaming(object sender, EventArgs e)
{
Console.WriteLine("cat's awake, run quick!");
}
}
}
.
- Follow-Ups:
- Re: About the remoting event
- From: Nicholas Paldino [.NET/C# MVP]
- Re: About the remoting event
- Prev by Date: Re: AJAX
- Next by Date: Re: PrintForm in Hight quality
- Previous by thread: Re: convert query to DLinq
- Next by thread: Re: About the remoting event
- Index(es):
Relevant Pages
|