private static void CreateRemoteRequestListener()
{
IDictionary dict = new Hashtable(2);
dict["name"] = "FW App Instance Listener";
int maxPort = kStartingPort + 100;
Exception lastException = null;
bool fFoundAvailablePort = false;
for (int port = kStartingPort; !fFoundAvailablePort && port < maxPort; port++)
{
try
{
dict["port"] = port;
// Set up the server channel.
TcpChannel instanceListener = new TcpChannel(dict, null, null);
ChannelServices.RegisterChannel(instanceListener, false);
RemotingConfiguration.ApplicationName = FwUtils.ksSuiteName;
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteRequest),
kFwRemoteRequest, WellKnownObjectMode.Singleton);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(PaRemoteRequest),
kPaRemoteRequest, WellKnownObjectMode.Singleton);
fFoundAvailablePort = true;
s_serviceChannel = instanceListener;
s_servicePort = port;
Logger.WriteEvent("Listening on port " + port);
}
catch (Exception e)
{
Logger.WriteEvent("Attempt to listen on port " + port + " failed.");
Logger.WriteError(e);
// Keep trying different ports until we find an available one.
lastException = e;
}
}
if (!fFoundAvailablePort)
throw new RemotingException("Could not find any available port for listening.", lastException);
}