Creating a Service on “any free port”
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 ServiceEndpoint.ListenUriMode to ListenUriMode.Unique (the default is ListenUriMode.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.
May 6th, 2006 at 1:31 am
[…] […]
May 13th, 2006 at 4:56 am
Finally, I have been looking for this feature since WSE2.
I’m so glad you have post this message.
Thank you,
Ido.
May 16th, 2006 at 11:11 am
[…] I wrote earlier about how to write a Service that listens on any free port. If you are programming at the Channel/Binding layer directly, the easiest way to autogenerate a ListenUri is to call the following method on your Binding: public IChannelListener<TChannel> BuildChannelListener<TChannel>(params object[] parameters) […]
August 18th, 2006 at 5:19 pm
[…] Your port# is usually specified in the URI of your endpoint (see RFC 2396, section 3.2.2). If a port# is not specified then each URI scheme has the option of supporting a default port# (HTTP uses 80, HTTPS uses 443, net.tcp uses 808, etc.). You can also configure a WCF endpoint to listen on any available port# for client-side or Discovery/registry purposes. […]