O
Olie
I have a number of applications that need to access the same object at
different times and any one of these programs may be running at any one
time. I do not have a specific application that could act as the
server. So I want to give each application the capability of being the
server and the first one to start gets the job.
Unfortunately to do this I need some way of detecting whether a server
is already running. I was hoping that Activator.GetObject() might
return null if there is no server but it just returns a usless object
that throws an exception every time you try and use it.
Is there any way without using exceptions (which are slow and horrible)
to find out if another server is running?
I have posted my code bellow to help you understand what I mean. Both
functions are calling by any program wishing to access the remoted
object.
I also have the same problem with Channels.
Thanks for any help!
Olie
public void StartService(string Name,Type type)
{
if (_ServerChannel == null)
{
try
{
BinaryClientFormatterSinkProvider ClientProvider =
new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ServerProvider =
new BinaryServerFormatterSinkProvider();
System.Collections.Hashtable Properties = new
System.Collections.Hashtable();
ServerProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
Properties["port"] = xxxx;
Properties["name"] = "xxxx";
Properties["typeFilterLevel"] = "Full";
_ServerChannel = new TcpChannel(Properties,
ClientProvider, ServerProvider);
ChannelServices.RegisterChannel(_ServerChannel);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
RemotingConfiguration.RegisterWellKnownServiceType(type,
Name, WellKnownObjectMode.Singleton);
}
public void ConnectToService(string Url, string Name, Type
type, ref XxxxService Endpoint)
{
if (_Channel == null)
{
BinaryClientFormatterSinkProvider ClientProvider = new
BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ServerProvider = new
BinaryServerFormatterSinkProvider();
System.Collections.Hashtable Properties = new
System.Collections.Hashtable();
ServerProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
Properties["port"] = 0;
_Channel = new TcpChannel(Properties, ClientProvider,
ServerProvider);
ChannelServices.RegisterChannel(_Channel);
}
Endpoint = (AcwService)Activator.GetObject(type, "tcp://" +
Url + ":xxxx/" + Name);
Register(Endpoint);
}
different times and any one of these programs may be running at any one
time. I do not have a specific application that could act as the
server. So I want to give each application the capability of being the
server and the first one to start gets the job.
Unfortunately to do this I need some way of detecting whether a server
is already running. I was hoping that Activator.GetObject() might
return null if there is no server but it just returns a usless object
that throws an exception every time you try and use it.
Is there any way without using exceptions (which are slow and horrible)
to find out if another server is running?
I have posted my code bellow to help you understand what I mean. Both
functions are calling by any program wishing to access the remoted
object.
I also have the same problem with Channels.
Thanks for any help!
Olie
public void StartService(string Name,Type type)
{
if (_ServerChannel == null)
{
try
{
BinaryClientFormatterSinkProvider ClientProvider =
new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ServerProvider =
new BinaryServerFormatterSinkProvider();
System.Collections.Hashtable Properties = new
System.Collections.Hashtable();
ServerProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
Properties["port"] = xxxx;
Properties["name"] = "xxxx";
Properties["typeFilterLevel"] = "Full";
_ServerChannel = new TcpChannel(Properties,
ClientProvider, ServerProvider);
ChannelServices.RegisterChannel(_ServerChannel);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
RemotingConfiguration.RegisterWellKnownServiceType(type,
Name, WellKnownObjectMode.Singleton);
}
public void ConnectToService(string Url, string Name, Type
type, ref XxxxService Endpoint)
{
if (_Channel == null)
{
BinaryClientFormatterSinkProvider ClientProvider = new
BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ServerProvider = new
BinaryServerFormatterSinkProvider();
System.Collections.Hashtable Properties = new
System.Collections.Hashtable();
ServerProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
Properties["port"] = 0;
_Channel = new TcpChannel(Properties, ClientProvider,
ServerProvider);
ChannelServices.RegisterChannel(_Channel);
}
Endpoint = (AcwService)Activator.GetObject(type, "tcp://" +
Url + ":xxxx/" + Name);
Register(Endpoint);
}