Is it possible to make it so that when you start the WCF service, if the same service with the same URI is running on the same machine, the old service will close first and then the new one will open. For example, the service will start with a different account

    1 answer 1

    Each WCF instance listens to a specific port, for example 80, 8000, 8080, or some other.

    If you try to run the second copy without extinguishing the first copy, you will get a "port busy" error.

    Therefore, if such a mechanism is very, very necessary, then in principle it is possible, but you need to check whether the port is busy before the start, and also be able to give the command to the running instance to close.

    • A small amendment. A busy port is not a problem, because in WCF different applications can listen to the same port. The problem is that they are trying to listen to the same URL ... - Pavel Mayorov
    • @PavelMayorov I never thought about such subtlety, I only know that when you accidentally launch another copy of the service, you will immediately receive a swearing at the busy port. At least, I thought that two applications could not listen to the same port. It turns out that the combination of url + port is checked for uniqueness, and not just a port? I thought that the OS itself forbids listening to one port to different programs. - AK
    • 2
      This is if you use winsockets. But WCF does not use them ... If binding by http or net.tcp with the sharing port enabled. - Pavel Mayorov