How does ListenUriMode.Unique work for clients?

2019-02-20 01:54发布

问题:

I'm writing a WCF service, and am attempting to avoid getting AddressAlreadyInUseException when my port is already taken. This answer points toward using ListenUriMode.Unique to solve this problem. From MSDN, it appears that this option would cause my service to automatically choose an available port:

For TCP in exclusive mode (PortSharingEnabled is false) this means binding to a uniquely available port number.

My question is, if my port number is being chosen at runtime, how would my client know what port number to use?

回答1:

You'll have to use WCF Discovery to discover the service.