Hi,
I am using remoting to pass in parameters from new launches of an application. So basically I have
only one instance of the application and I am using remoting to pass the parameters.
The problem is as follows:
I can remote call the first few times, but then I get the
"No connection could be made because target machine actively refused it 127.0.0.1:8084"
I don't have a firewall turned on, so I am slightly baffled as to why it would stop working.
I have attached the cut out of the code in question and below is the code used to call the code.
Below code for creating server class
-------------------------------------
RemotingService<ServiceDelegatorMainrs = new RemotingService<ServiceDelegatorMain>();
rs.ServiceCreate();
Delegator = rs.ServerService;
-------------------------------------
Below code for creating client class
-------------------------------------
RemotingClient<IMainrc = new RemotingClient<IMain>(); //Client will only see what the IMain
interface defines.
rc.RemoteService.RemoteServiceMain(args);
-------------------------------------
Now for some unknown reason, the RemotingService class gets deconstructed, before the application
ends. This shouldn't happen. Once the class instance is created it is left alone and should only be
terminated when the application ends.
Nothing touches the instances.
When I run the application through VS2008 everything works fine. Also when run do a ***Debug***
build , it works fine.
ONLY a Release build doesn't work. So that makes it even more confusing.
The remoting code is 100% functioning and the class the receives the remote does nothing now as I
commented the code out. I've created a new skeleton project with the code and that project works
100%..
Why would other forms that have nothing with the class in question affect the outcome.
What gives? I can't help but think this is a VS2008 bug. I have no qualms in releasing a fully
functioning Debug build rather than a none working release.
If you want me to upload a testapplicaiton sample, please let me know and I will.
Any help is much appreciated.
Adhal
#region Remote Server
/// <summary>
/// Server that is going to provide remote services
/// </summary>
/// <typeparam name="T">Definition of the class that is going to registered for remote access.</typeparam>
class RemotingService<Twhere T : MarshalByRefObject, new() //MarshalByRefObject to allow it to be referenced
{
private static TcpChannel _TCPChannel = null;
private T _ServerService = null;
private int _Port = 8084;
private string _ServerName = "GenericRemotingService";
public T ServerService
{
get { return _ServerService; }
set { _ServerService = value; }
}
public int Port
{
get { return _Port; }
set { _Port = value; }
}
public string ServerName
{
get { return _ServerName; }
set { _ServerName = value; }
}
/// <summary>
/// Defaults:
/// P: 8084
/// Server name : GenericRemotingService
/// </summary>
public RemotingService() { }
private void CreateChannel()
{
if (_TCPChannel == null)
{
_TCPChannel = new TcpChannel(8084);
ChannelServices.RegisterChannel(_TCPChannel, false);
RemotingConfiguration.RegisterWellKnownServiceType (typeof(T), _ServerName, WellKnownObjectMode.SingleCall);
}
}
/// <summary>
/// Default Setting. Creates an instance of T
/// </summary>
public void ServiceCreate()
{
if (_TCPChannel == null)
{
_ServerService = new T();
CreateChannel();
}
}
/// <summary>
/// Server Service instant already exists so just pass refernce
/// </summary>
/// <param name="ServerService">Server Service instant already exists so just pass refernce</param>
public void ServiceCreate(T ServerService)
{
_ServerService = ServerService;
CreateChannel();
}
~RemotingService()
{
if (_TCPChannel != null)
{
_TCPChannel.StopListening(null);
_TCPChannel = null;
}
}
}
#endregion
#region Remote Client
/// <summary>
/// Client that is going to use remote service
/// </summary>
/// <typeparam name="T">Definition of the class registered at the server</typeparam>
class RemotingClient<T>
{
private static string _URL = "tcp://localhost:8084/GenericRemotingService";
private TcpChannel _TCPChannel;
private T _RemoteService;
public T RemoteService
{
get { return _RemoteService; }
}
/// <summary>
/// Default URL "tcp://localhost:8084/GenericRemotingService"
/// Default Uses ServiceDelegateMain
/// </summary>
public RemotingClient() : this(_URL) { }
/// <summary>
///
/// </summary>
/// <param name="URL">Should include port & service name</param>
public RemotingClient(string URL)
{
_URL = URL;
_TCPChannel = new TcpChannel();
ChannelServices.RegisterChannel(_TCPChannel, false);
_RemoteService = (T)Activator.GetObject(typeof(T), _URL);
}
~RemotingClient()
{
if (_TCPChannel != null)
{
_TCPChannel.StopListening(null);
_TCPChannel = null;
}
}
}
#endregion Client