I have a WCF service running locally. The service has a default port on which it is running, but if this port is already in use, I assign the port dynamically.
I added this to the host to make it available:
serviceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior()); serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());
Now my client needs to connect to this host. In the client, I want him to try the default port first, and if he cannot connect to the service on the default port, then he will open.
I found that this discovery takes about 20-30 seconds, so I would prefer to avoid it only when it cannot find the host on the default port.
So my question is: what is the fastest way to determine if my host is on the default port?
I was thinking of doing something like setting an open timeout on the client for 10 seconds and then trying / catching on open, but it still takes 10 seconds to wait.
source share