Hi there,
Days ago, i ran into a serious problem. I´m using DNS round robin in a
..NET Remoting application. But, as long as the .NET Remoting makes a
sort of cache of each connection made. If you try to connect to a
server as mycomputer:3001, that is an alias to the round robin, the
..NET Remoting will cache the IP address returned from the DNS server,
and each subsequent request to the alias will be redirected to the
first ip address cached by the .NET Remoting, doing this the .NET
Remoting don´t resolve the alias to get the new ip address.
So, looking through the TcpChannels, i found out the
TcpClientTransportSink, which have a private member of the class
ClientSocketCache, which caches all the remoting connections already
made by the client into a Hashtable.
Via reflection i've accessed this hashtable and cleared it, solving my
problem.
I hope that it would be usefull.
Thiago Oliveira.
Type channelsvc = Type.GetType("System.Runtime.Remoting.Channels.ChannelServices");
object sink =
channelsvc.InvokeMember("GetChannelSinkForProxy",
BindingFlags.InvokeMethod | BindingFlags.Static |
BindingFlags.NonPublic, null, null, new object[] { proxy });
IClientChannelSink sink1 =
(IClientChannelSink)sink; // Get The BinaryFormatter Sink
IClientChannelSink sink2 = sink1.NextChannelSink;
// Get The TcpClientTransport Sink
// Iterates through the sinks 'till find the
TcpClientTransportSink
while (sink1 != null && sink1.NextChannelSink !=
null)
{
sink2 = sink1.NextChannelSink;
sink1 = sink2.NextChannelSink;
}
Type TcpClientTransportSink = sink2.GetType();
FieldInfo fClientSocketCache =
TcpClientTransportSink.GetField("ClientSocketCache",
BindingFlags.NonPublic | BindingFlags.Instance);
object ClientSocketCache =
fClientSocketCache.GetValue(sink2);
FieldInfo f_connections =
ClientSocketCache.GetType().GetField("_connections",
BindingFlags.NonPublic | BindingFlags.Static);
Hashtable _connections =
(Hashtable)f_connections.GetValue(null);
_connections.Clear();