WCF DiscoverClient.FindAsync throws SocketException


We have a WCF service

var address = string.Format("net.tcp://{0}", _settings.ServerAddress);
var binding = new NetTcpBinding(SecurityMode.None) { HostNameComparisonMode = HostNameComparisonMode.Exact };

var service = new LicenseService();

_host = new ServiceHost(service);
_host.AddServiceEndpoint(typeof(ILicenseService), binding, address);
_host.AddServiceEndpoint(typeof(ILicenseServiceAdmin), binding, address);

_host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
_host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());


and the client

var searchCriteria = new FindCriteria(typeof(Utils.Licensing.ILicenseService));
_discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
_discoveryClient.FindProgressChanged += Client_FindProgressChanged;
_discoveryClient.FindCompleted += Client_FindCompleted;
_discoveryClient.FindAsync(searchCriteria, _syncObject);

It works fine for all of our customers except one who recently reported the following error:

System.Net.Sockets.SocketException (0x80004005): Ein ung├╝ltiges Argument wurde angegeben at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) at System.ServiceModel.Channels.UdpUtility.CreateListenSocket(IPAddress ipAddress, Int32& port, Int32 receiveBufferSize, Int32 timeToLive, Int32 interfaceIndex, Boolean allowMulticastLoopback, Boolean isLoopbackAdapter) at System.ServiceModel.Channels.UdpChannelFactory'1.GetSockets(Uri via, IPEndPoint& remoteEndPoint, Boolean& isMulticast) at System.ServiceModel.Channels.UdpChannelFactory'1.OnCreateChannel(EndpointAddress to, Uri via) at System.ServiceModel.Channels.ChannelFactoryBase'1.InternalCreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.Channels.ServiceChannelFactory.ServiceChannelFactoryOverDuplex.CreateInnerChannelBinder(EndpointAddress to, Uri via) at System.ServiceModel.Channels.ServiceChannelFactory.CreateServiceChannel(EndpointAddress address, Uri via) at System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel(Type channelType, EndpointAddress address, Uri via) at System.ServiceModel.DuplexChannelFactory'1.CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via) at System.ServiceModel.ClientBase'1.CreateChannel() at System.ServiceModel.ClientBase'1.CreateChannelInternal() at System.ServiceModel.ClientBase'1.get_Channel() at System.ServiceModel.ClientBase'1.get_InnerChannel() at System.ServiceModel.Discovery.DiscoveryClient.FindAsync(FindCriteria criteria, Object userState)

All necessary rules are added to the Firewall. We also tried to play with the rules but the code either finds the service or doesn't. It never throws the exception though.

We have no a physical access to the client's computer and the main difficulty for us is to reproduce this error.

Would appreciate any help.

EDIT 2019-10-22

It turned out that the customer run the WCF client from a shared folder. The socket connection failed due to the security settings. It is not clear which settings play role here, however, after copying the WCF client locally the problem has gone.

asked on Stack Overflow Oct 17, 2019 by Sergey • edited Oct 22, 2019 by Sergey

1 Answer


There is no problem with your code, I tested it and found that the client code can find the service address correctly. This may be a configuration problem on the client-side. For example, is the service contract shared by the server and the client consistent, and the search condition parameters?
Furthermore, the error reported by the client seems to be a non-English language, "specified invalid parameters"? Can you give me the English version of the error message? I have not encountered a similar problem, but it is all about the client-side instead of the server-side.
Feel free to let me know if there is anything I can help with.

answered on Stack Overflow Oct 18, 2019 by Abraham Qian

User contributions licensed under CC BY-SA 3.0