472,356 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

.NET Remoting, Event Subscription to the Remoting Object / Subscribed event does not fire...

Hi,
I am very new to .NET Remoting and I try to run a simple program to
subscribe to an event raised by Remoting Class. The Remoting Server
initiates an instance of Remoting Class as Singleton / Server
activated mode on startup. The Remoting Client accesses the Remoting
Class through the interface of the Class and subscribes to an event
of
the Remoting Class that will be fired upon the private member value
change.

The problem is that I can not get the subscribed event fired. Do I
miss a point about Client Registration / Server Registration such
that
2 instances are created, 1 on Server Side, 1 on Client Side and the
event subscription is done on the wrong one? Please help :) Thanks in
advance...
[Remoting Class]
public class NetworkElement : MarshalByRefObject, INetworkElement
{
public event AlarmEventHandler AlarmEvent;
private Boolean _ACFail;
public Boolean ACFail
{
get { return _ACFail; }
set
{
_ACFail = value;
OnAlarmsEvent(new AlarmEventArgs(1));
}
}
protected void OnAlarmsEvent(AlarmEventArgs arg)
{
if (AlarmEvent != null) AlarmEvent(this, arg);
}
public void AddAlarmEvent(AlarmEventHandler handler)
{
AlarmEvent += handler;
}
}
[Interface for Remoting Class]
public delegate void AlarmEventHandler(object sender,
AlarmEventArgs arg);
[Serializable]
public class AlarmEventArgs : EventArgs
{
private Int32 _AlarmType;
public Int32 AlarmType
{
get { return _AlarmType; }
}
public AlarmEventArgs(Int32 Type)
{
_AlarmType = Type;
}
}
public interface INetworkElement
{
void AddAlarmEvent(AlarmEventHandler handler);
}
[The Remoting Client]
public class Client : MarshalByRefObject
{
public void SubscribeToAlarmEvent()
{
RemotingConfiguration.Configure("Client.exe.config ");
WellKnownClientTypeEntry[] entry =
RemotingConfiguration.GetRegisteredWellKnownClient Types();
INetworkElement ine =
(INetworkElement)Activator.GetObject(entry[0].ObjectType,
entry[0].ObjectUrl);
ine.AddAlarmEvent(new
AlarmEventHandler(ClientEventHandler));
AlarmType = -1;
}
public void ClientEventHandler(object sender, AlarmEventArgs
arg)
{
AlarmType = arg.AlarmType;
}
}
config files are :
[Server.exe.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="6000" displayName="ServerChannel" ref="tcp">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"</
formatter>
</serverProviders>
<clientProviders>
<formatter ref="binary"></formatter>
</clientProviders>
</channel>
</channels>
<service>
<wellknown type="NetworkE.NetworkElement, NetworkElement"
objectUri="NetworkElement.rem" mode="Singleton">
</wellknown>
</service>
</application>
</system.runtime.remoting>
</configuration>
[Client.exe.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="0" displayName="ClientChannel" ref="tcp">
<clientProviders>
<formatter ref="binary"></formatter>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"></
formatter>
</serverProviders>
</channel>
</channels>
<client>
<wellknown type="INetworkE.INetworkElement, INetworkElement"
url="tcp://localhost:6000/NetworkElement.rem">
</wellknown>
</client>
</application>
</system.runtime.remoting>
</configuration>

Apr 13 '07 #1
2 2937
This is a common question - see
http://www.google.sk/search?hl=sk&q=...g+events&meta= with many
relevant results.

"erbilkonuk" <er********@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Hi,
I am very new to .NET Remoting and I try to run a simple program to
subscribe to an event raised by Remoting Class. The Remoting Server
initiates an instance of Remoting Class as Singleton / Server
activated mode on startup. The Remoting Client accesses the Remoting
Class through the interface of the Class and subscribes to an event
of
the Remoting Class that will be fired upon the private member value
change.

The problem is that I can not get the subscribed event fired. Do I
miss a point about Client Registration / Server Registration such
that
2 instances are created, 1 on Server Side, 1 on Client Side and the
event subscription is done on the wrong one? Please help :) Thanks in
advance...
[Remoting Class]
public class NetworkElement : MarshalByRefObject, INetworkElement
{
public event AlarmEventHandler AlarmEvent;
private Boolean _ACFail;
public Boolean ACFail
{
get { return _ACFail; }
set
{
_ACFail = value;
OnAlarmsEvent(new AlarmEventArgs(1));
}
}
protected void OnAlarmsEvent(AlarmEventArgs arg)
{
if (AlarmEvent != null) AlarmEvent(this, arg);
}
public void AddAlarmEvent(AlarmEventHandler handler)
{
AlarmEvent += handler;
}
}
[Interface for Remoting Class]
public delegate void AlarmEventHandler(object sender,
AlarmEventArgs arg);
[Serializable]
public class AlarmEventArgs : EventArgs
{
private Int32 _AlarmType;
public Int32 AlarmType
{
get { return _AlarmType; }
}
public AlarmEventArgs(Int32 Type)
{
_AlarmType = Type;
}
}
public interface INetworkElement
{
void AddAlarmEvent(AlarmEventHandler handler);
}
[The Remoting Client]
public class Client : MarshalByRefObject
{
public void SubscribeToAlarmEvent()
{
RemotingConfiguration.Configure("Client.exe.config ");
WellKnownClientTypeEntry[] entry =
RemotingConfiguration.GetRegisteredWellKnownClient Types();
INetworkElement ine =
(INetworkElement)Activator.GetObject(entry[0].ObjectType,
entry[0].ObjectUrl);
ine.AddAlarmEvent(new
AlarmEventHandler(ClientEventHandler));
AlarmType = -1;
}
public void ClientEventHandler(object sender, AlarmEventArgs
arg)
{
AlarmType = arg.AlarmType;
}
}
config files are :
[Server.exe.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="6000" displayName="ServerChannel" ref="tcp">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"</
formatter>
</serverProviders>
<clientProviders>
<formatter ref="binary"></formatter>
</clientProviders>
</channel>
</channels>
<service>
<wellknown type="NetworkE.NetworkElement, NetworkElement"
objectUri="NetworkElement.rem" mode="Singleton">
</wellknown>
</service>
</application>
</system.runtime.remoting>
</configuration>
[Client.exe.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="0" displayName="ClientChannel" ref="tcp">
<clientProviders>
<formatter ref="binary"></formatter>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"></
formatter>
</serverProviders>
</channel>
</channels>
<client>
<wellknown type="INetworkE.INetworkElement, INetworkElement"
url="tcp://localhost:6000/NetworkElement.rem">
</wellknown>
</client>
</application>
</system.runtime.remoting>
</configuration>

Apr 13 '07 #2
More likely than not, your service is not aware of the type of the
client (which is understandable). Events on objects that are exposed by
services are generally a bad idea.

What you want to do is create a proxy class which exposes the events you
want to fire. It should also implement an interface that has methods that
correspond to the event signatures. This proxy and the interface should
reside in a dll that is outside of the service and the client, but
referenced by both.

Then, you have a method on the service which you can use to register the
INTERFACE (not the actual type). Of course, the implementation of the proxy
derives from MarshalByRefObject.

Then, when you want to fire the event, the service calls the method on
the interface, which will then trigger the event in the proxy, which the
client will have subscribed to.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"erbilkonuk" <er********@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Hi,
I am very new to .NET Remoting and I try to run a simple program to
subscribe to an event raised by Remoting Class. The Remoting Server
initiates an instance of Remoting Class as Singleton / Server
activated mode on startup. The Remoting Client accesses the Remoting
Class through the interface of the Class and subscribes to an event
of
the Remoting Class that will be fired upon the private member value
change.

The problem is that I can not get the subscribed event fired. Do I
miss a point about Client Registration / Server Registration such
that
2 instances are created, 1 on Server Side, 1 on Client Side and the
event subscription is done on the wrong one? Please help :) Thanks in
advance...
[Remoting Class]
public class NetworkElement : MarshalByRefObject, INetworkElement
{
public event AlarmEventHandler AlarmEvent;
private Boolean _ACFail;
public Boolean ACFail
{
get { return _ACFail; }
set
{
_ACFail = value;
OnAlarmsEvent(new AlarmEventArgs(1));
}
}
protected void OnAlarmsEvent(AlarmEventArgs arg)
{
if (AlarmEvent != null) AlarmEvent(this, arg);
}
public void AddAlarmEvent(AlarmEventHandler handler)
{
AlarmEvent += handler;
}
}
[Interface for Remoting Class]
public delegate void AlarmEventHandler(object sender,
AlarmEventArgs arg);
[Serializable]
public class AlarmEventArgs : EventArgs
{
private Int32 _AlarmType;
public Int32 AlarmType
{
get { return _AlarmType; }
}
public AlarmEventArgs(Int32 Type)
{
_AlarmType = Type;
}
}
public interface INetworkElement
{
void AddAlarmEvent(AlarmEventHandler handler);
}
[The Remoting Client]
public class Client : MarshalByRefObject
{
public void SubscribeToAlarmEvent()
{
RemotingConfiguration.Configure("Client.exe.config ");
WellKnownClientTypeEntry[] entry =
RemotingConfiguration.GetRegisteredWellKnownClient Types();
INetworkElement ine =
(INetworkElement)Activator.GetObject(entry[0].ObjectType,
entry[0].ObjectUrl);
ine.AddAlarmEvent(new
AlarmEventHandler(ClientEventHandler));
AlarmType = -1;
}
public void ClientEventHandler(object sender, AlarmEventArgs
arg)
{
AlarmType = arg.AlarmType;
}
}
config files are :
[Server.exe.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="6000" displayName="ServerChannel" ref="tcp">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"</
formatter>
</serverProviders>
<clientProviders>
<formatter ref="binary"></formatter>
</clientProviders>
</channel>
</channels>
<service>
<wellknown type="NetworkE.NetworkElement, NetworkElement"
objectUri="NetworkElement.rem" mode="Singleton">
</wellknown>
</service>
</application>
</system.runtime.remoting>
</configuration>
[Client.exe.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel port="0" displayName="ClientChannel" ref="tcp">
<clientProviders>
<formatter ref="binary"></formatter>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"></
formatter>
</serverProviders>
</channel>
</channels>
<client>
<wellknown type="INetworkE.INetworkElement, INetworkElement"
url="tcp://localhost:6000/NetworkElement.rem">
</wellknown>
</client>
</application>
</system.runtime.remoting>
</configuration>

Apr 13 '07 #3

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

Similar topics

21
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
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...
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...
5
by: Mark Overstreet | last post by:
I am writing an app that needs to contain an object model that allows it to be controlled similiar to something like Word. However, I am writing this in C# and all managed code. I know that I can...
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...
9
by: Nak | last post by:
Hi there, I have been messing around with remoting in an attempt to create a "shared application" as mentioned in another thread by that name. I have created a singleton object just like the...
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...
13
by: dmeglio | last post by:
Hello, I'm aware that when an EventHandler is created, it creates a reference to the object, therefore preventing GCing. Therefore, I've been implementing IDisposable in my controls to...
6
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.