1

I have a C++ Windows service exposing a .Net Remoting interface for a local client to use and everything works great until the IP address changes.

Since I have to support .Net 2.0, switching to WCF isn't an option.

Any ideas on what I can do?

Here's how I set up the channel:

Hashtable^ dict = gcnew Hashtable();
dict["port"] = 9085;
dict["authenticationMode"] = "IdentifyCallers";
dict["impersonate"] = nullptr;  
dict["secure"] = true;
dict["typeFilterLevel"] = "Full"; 

TcpServerChannel^ tcpChannel;
try
{
  tcpChannel = gcnew TcpServerChannel( dict, nullptr);
}
catch (Exception^ e)
{
}

try
{
  ChannelServices::RegisterChannel(tcpChannel, true);
}
catch (RemotingException^ RemoteException)
{
  return FALSE;
}
catch (Exception^ e)    {    }

MyServiceProxy^ proxy = gcnew MyServiceProxy(m_pService);
RemotingServices::Marshal(proxy,"ServiceProxy");

Here's how I'm connecting to that service via C#

    IDictionary dict = new Hashtable();
    dict["port"] = 9085;
    dict["name"] = "127.0.0.1";
    dict["secure"] = true;
    dict["tokenImpersonationLevel"] = "Impersonation";
    dict["typeFilterLevel"] = "Full";
    dict["connectionTimeout"] = 10000; // 10 seconds timeout
    workChannel = new TcpClientChannel(dict, null);
    try
    {
      ChannelServices.RegisterChannel(workChannel, true);
    }
    catch (System.Exception /*e*/)
    {
    }
    string objectPath = "tcp://127.0.0.1:9085/ServiceProxy";
    obj = (IMyService)Activator.GetObject(typeof(IMyService), objectPath);

I mean when the computers IP address changes. So here's the flow. Start the service which sets up the channel, then close the laptop lid, go home, open it back up again, get assigned a new IP address, now when I try to start the client and it can't connect the the service.

Iunknown
  • 347
  • 1
  • 2
  • 16
  • .Net 2.0 is over 10 years old, but we still have customers running Server 2003. – Iunknown Mar 08 '15 at 04:52
  • Some clarification on what "until the IP address changes" means could be useful... There is really no other place like 127.0.0.1 - not sure why you try to change that into anything else. – Alexei Levenkov Mar 08 '15 at 05:41
  • Sorry about that. I mean the computers IP address changes. So here's the flow. Start the service which sets up the channel, then they close the laptop lid, go home, open it back up again, get assigned a new IP addess, now the client can't connect the the service channel anymore. – Iunknown Mar 08 '15 at 16:02
  • you should edit question with this information. Additionally I'd recommend to clarify if issue is only with already running client OR even new client is not able to connect. – Alexei Levenkov Mar 08 '15 at 18:54
  • I know a new client cannot connect until I bounce the service. Then it can connect. I'll update the original post when I get to a real computer. – Iunknown Mar 08 '15 at 20:18

1 Answers1

1

After a good bit of research, I ran across the 'bindTo' parameter...and all I needed to do was to add the parameter to the TCPServerChannel dictionary.

dict["bindTo"]= "127.0.0.1";

If this didn't work, I was going to try to using the IPCServerChannel, but thankfully this one line was all I needed.

And to think, this one line has caused so much grief.

Thank you Alexei for helping.

Iunknown
  • 347
  • 1
  • 2
  • 16