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>