ListenUriMode.Unique

Service Station, by Aaron Skonnard

Syndication

This is one my favorite WCF features that I've stumbled across lately. Kenny was the first to mention it on his blog. It basically solves the challenge of generating a "unique" address for an endpoint when you don't know what's already in use. Here's how it works:
 
<configuration>
  <system.serviceModel>
    <services>
      <service name="WcfTests.MathService">
        <endpoint listenUriMode="Unique"
                  address="net.tcp://localhost/math"
                  binding="netTcpBinding"
                  contract="WcfTests.MathService"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>
 
Using this configuration with TCP endpoints causes WCF to automatically choose a "free" port number -- it also appends a unique GUID to the end of the address to ensure uniqueness. For HTTP and named pipes it only appends the GUID to the address, it doesn't generate a unique port number.
 
When I run this configuration, the listener address for this endpoint is:
 
net.tcp://localhost:39619/math/908ae8dc-7427-407a-9ea4-8aeecdfa62be
 
The default for listenUriMode is "Explicit", which allows you to "explicitly" control the addresses.
 

Posted Apr 24 2006, 07:05 PM by Aaron Skonnard
Filed under: ,

Comments

Christian Weyer wrote re: ListenUriMode.Unique
on 04-26-2006 12:04 AM
You should mention that consumers can then walk up to the service's base address (hopfully it is enabled ;)) and retrieve the necessary metadata which obviously also includes the endpoint address.
Therefore this approach is a bit hard to use if you do contracts assembly sharing in a 'closed' development environment where you usually have to know the endpoint address upfront.

Of course you could then go along this route for obtaining the metadata dynamically:
http://blogs.thinktecture.com/cweyer/archive/2006/04/06/414456.aspx

Aaron Skonnard wrote re: ListenUriMode.Unique
on 04-26-2006 8:36 AM
Actually, it's even hard using MEX because the listenUri address (the dynamically generated one) doesn't show up in the WSDL like you might expect it to in a Via element. I've asked the team about this and they say it's "by design". When using this approach you have to use an out-of-band mechanism to exchange the listenUri address.
Christian Weyer wrote re: ListenUriMode.Unique
on 04-26-2006 9:58 AM
Doh - this is not a good design then :(

Add a Comment

(required)  
(optional)
(required)  
Remember Me?