Specifying a ListenUri for a WCF Adapter Receive Location

When configuring a receive location using the WCF-Custom adapter, there is a textbox for specifying the endpoint address on the General tab of the configuration dialogs. There is however no field where you can specify values for the ListenUri and ListenUriMode values for the endpoint.

One way is to write a custom endpoint behavior which can set these values on the endpoint. However, when I attempted to do so, I realized that it didn’t work – no matter where I tried modifying the ServiceEndpoint.ListenUri property (in either the AddBindingParameters() function, or the ApplyDispatchBehavior() function) – my modifications to the ListenUri property were ignored by the WCF Runtime.

I finally found another workaround – you can use your endpoint behavior to inject a custom binding element into the stack (at the top). Then, when the BuildChannelListener() function is called, simply pass back the inner channel listener (created by calling the function BuildInnerChannelListener() function on the BindingContext) – but, before you call that method, you can modify the ListenUriBaseAddress property on the BindingContext.

Attached is some sample code that demonstrates this. There is a .NET console application for the service with one service endpoint, with the logical address as https://dummyAddress. Rather than specifying the listenUri in the endpoint configuration, its being specified via my custom behavior (which in turns add a custom binding element). There is a .NET console application for the client, which uses the clientVia behavior. And there is the ListenUriBehavior project.

You should be able to use this ListenUriBehavior endpoint behavior in BizTalk too, by specifying it in the Behaviors tab in the Receive Location configuration. Remember that your behavior dll needs to be GACed, and your behavior needs to be registered in machine.config for this. The entry to be added to machine.config is present (as a comment) in the "ListenUriBehaviorExtensionElement.cs" file.

SimpleClientServer.zip