473,378 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

Jul 1 '08 #1
2 3487
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 MarshalByRefObject, 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]
- mv*@spam.guard.caspershouse.com

"fairyvoice" <fa********@discussions.microsoft.comwrote in message
news:46**********************************@microsof t.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.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!");
}
}
}

Jul 1 '08 #2
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 MarshalByRefObject, 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]
- mv*@spam.guard.caspershouse.com

"fairyvoice" <fa********@discussions.microsoft.comwrote in message
news:46**********************************@microsof t.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.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!");
}
}
}


Jul 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nick | last post by:
Is there a way that if I host my remoted object in IIS (not having to mess with encryption & authentication via a custom sink) that the server can raise events and the clients can detect them? If...
1
by: Dan Cimpoiesu | last post by:
I have a remoting object, derived from MarshalByRefComponent, that I instantiate on the client side, with Activator.GetObject. Can I receive events fired on the server, on the client? How?
2
by: wobbles | last post by:
Hi Everyone (Happy New Year!), If I have clients that want to tell the server that something has happened, what would be the difference between "remoting events" and using an asynchronous (one...
15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
3
by: S.Creek | last post by:
Hi, I am trying to build a multi clients application with C# that will send and receive messages using a listener on a server, the computers are all on the same LAN, the listener need to...
4
by: Sharon | last post by:
Hi, I'm using the remoting, and I have a remoting object that has a public event that other processes should register to it. But when the client process is registering to the remote event, it...
6
by: AMDRIT | last post by:
Hello folks, I appologize for the cross post, but I really need an answer on this: I do not think that I am seeing the whole picture here. I would like to create a windows service and a...
3
by: S Chapman | last post by:
I have a simple remote server object that raises an event when the list maintined by it changes. The idea is to enable the remote client to update the GUI when the server list changes. When the I...
4
by: Rich | last post by:
Can anyone suggest a good (current) tutorial on how to do basic remoting with C# (2005 express edition)?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.