I have followed this Microsoft article for installing WCF service as windows service (with netTCPbinding).
Following is the code for setting up the Announcement from the service side:
protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(MonitoringService));
ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
serviceDiscoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());
myServiceHost.Description.Behaviors.Add(serviceDiscoveryBehavior);
myServiceHost.Description.Endpoints.Add(new UdpDiscoveryEndpoint());
myServiceHost.Open();
}
The problem I am facing is, once the service becomes available (say after restart), it will notify the client that it's back but that notification is going to client two times and hence it is trying to perform some cleanup two times.
Following is the detail of the service, where it is running. (2772 is the PID of the service).
What I am suspecting is this service (for some reason) is listening "two times" on the same port (I don't know how this is possible) as we can see in two TCP rows, the status is listening. This might be the reason I am thinking that is causing the Online event triggered on the client side two times once the service comes online.
Please provide your inputs. I have followed the same steps for installation as mentioned in the above link.
EDIT
Why is this service shown two times, even for the same port?