Remoting: No connection could be made because target machine actively

A

Adhal

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<ServiceDelegatorMain> rs = new RemotingService<ServiceDelegatorMain>();
rs.ServiceCreate();
Delegator = rs.ServerService;
-------------------------------------


Below code for creating client class
-------------------------------------
RemotingClient<IMain> rc = 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<T> where 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
 
M

Mr. Arnold

<snipped>

Maybe, the asynchronous call has crashed on a thread and you don't know it.
I have seen it where the asynchronous call crashed on a spawned thread, the
application didn't know it and never terminated itself, but it just stopped
functioning.
 
A

Adhal

Mr. Arnold said:
Maybe, the asynchronous call has crashed on a thread and you don't know
it. I have seen it where the asynchronous call crashed on a spawned
thread, the application didn't know it and never terminated itself, but
it just stopped functioning.

Thanks Arnold,

I thought it might have been with the asynchronous call so I commented it out. Right now the
remoting part of the application does nothing except call an empty method.

****Also what is bugging more than anything is the Debug version works perfectly, and if I run the
release through VS2008 I get no errors.****

It only occurs on the exe Release build. I have created the project from scratch again and copied in
the code again manually making sure there isn't anything odd. Nothing. The Release should behave in
the same manner as the Debug.

Even when I haven't called the remote service, it closes the Service class sometimes. As though it
times out???

I think I might release the debug version.


???? I'm wearing off my scalp.
 
A

Adhal

???? I'm wearing off my scalp.
Finally figured it out. I had the RemotingService declared inside a method. Made it public and tada.
Strange that it should behave differently in debug and simpler applicatons
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top