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