By default, when creating a ServiceHost we require you to specify a base address (e.g. “http://kennyw.com/myService/”). This is because your clients needs to know where to send messages to. Sometimes you have a situation where you don’t need to know the exact address up front (let’s say you are using WS-Discovery or some other registry-based lookup). In that case, you want to indicate to the transport to “use any free port” (or “port 0” in sockets-speak). Fortunately, Indigo has this functionality baked into our addressing parameters.
To signal you want this behavior, set
.Unique (the default is
.Explicit). At build time this will propagate to
BindingContext.ListenUriMode, which will then cause the Transport to “unique-ify” the ListenUriBaseAddress.
For exclusive TCP (where the process is directly listening on a socket) we will bind to a uniquely available port#. For shared TCP, Pipes, and HTTP we will append a GUID to the base address which will uniquely identify this endpoint.