Building a "client-side" Listener

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)

For example: myListener = myBinding.BuildChannelListener<IInputChannel>();

The base class will expand this call out to create a Listener using the scheme from the binding, the hostname of the machine, and ListenUriMode.Unique to generate the rest of the ListenUri:

UriBuilder listenUriBuilder = new UriBuilder(this.Scheme, machineName);

return this.BuildChannelListener<TChannel>(listenUriBuilder.Uri, string.Empty, ListenUriMode.Unique, parameters);

Leave a Reply

Your email address will not be published. Required fields are marked *