By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,902 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,902 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.