Thibaud

Hi,

in my remoting server app, I have the following code:
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();

try
{
props["port"] = remotingPort;
TcpChannel channel = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(channel, false);
channelName = channel.ChannelName;


after this server having been closed and re-opened several times, and the client still running, I sometimes get a SocketException on the "new TcpChannel(props, null, provider)":
An invalid argument was supplied
StackTrace: at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.Net.Sockets.TcpListener.Start(Int32 backlog)
at System.Net.Sockets.TcpListener.Start()
at System.Runtime.Remoting.Channels.ExclusiveTcpListener.Start(Boolean exclusiveAddressUse)
at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel.StartListening(Object data)
at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel.SetupChannel()
at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel..ctor(IDictionary properties, IServerChannelSinkProvider sinkProvider, IAuthorizeRemotingConnection authorizeCallback)
at System.Runtime.Remoting.Channels.Tcp.TcpChannel..ctor(IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
at PCSuite.ServiceFactories.PCSuiteFramework.RegisterTcpChannel() in
D:\PC_Link_v1.0\dev\Dev\PCSuite\ServiceFactories\PCSuiteFramework.cs:line 118

If first thought it could be due to a bad channel unregistering, but the exception is not thrown on the RegisterChannel but in the TcpChannel constructor! And this also happens if I use the TcpChannel(port) constructor, with every port values, including dynamic port (0)!

Once I first got this exception, every time I close and restart the server I got the exception again. The only way of getting rid of it is to close the client.

Here's how I register the channel in the client:
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 0;
TcpChannel channel = new TcpChannel(props, null, provider);
if (ChannelServices.GetChannel(channel.ChannelName) == null)
ChannelServices.RegisterChannel(channel, false);

I do this in a loop, trying to register the channel every 3 seconds.

I unregister the channel (in the client and in the server) with a simple ChannelServices.UnregisterChannel(channel)

Unfortunately I've been stuck on this for a while, and not able to find anything about it :-(
Does anyone have an idea Am I doing something wrong

Thanks a lot!

Thibaud


Re: .NET Remoting and Runtime Serialization new TCPChannel() throws SocketException after several calls

Thibaud

Ok, I think I found!

The problem is that, in my client, I was unregistering the channel only at its shutdown, whereas it also needed to be unregistered after a remoting failure, typically when the server was not launched.

I had put the RegisterChannel code in a try/catch, and in the same try block, after the RegisterChannel, I was getting remote objects with Activator.GetObject. In the catch block, I was setting a flag indicating that the remoting init failed and needed to be re-tried x seconds later. But I was not unregistering the channel, whereas when the server was not launched, the client managed to register the channel: the exception was raised in the Activator.GetObject calls, not on the RegisterChannel! Thus many calls to RegisterChannel where made, without matching ChannelServices.UnregisterChannel
My mistake! But it's just a shame the exception message I was getting was not very 'clear': An invalide argument was supplied!!!
I've corrected this, and since then, could not be able to reproduce the error I had :-)




Re: .NET Remoting and Runtime Serialization new TCPChannel() throws SocketException after several calls

criszao

Try desabled your firewall or anything that deny your remoting open a port in server. resolved for me. sorry, my english is bad, but i think that i would help you...