Building a Composite Duplex Binding Element
I occasionally get requests to help people build what turns out to be a variation of our CompositeDuplexBindingElement. Composite duplex is just a channel shape changer that supports both reading and writing, and has independence between the connections on the two sides. The basic binding element for this shape changer really does not contain any deep functionality. If you need to build a similar type of shape changer, you can get most of the way there by doing only four things.
- Override CanBuildChannelFactory and CanBuildChannelListener to delegate down to the underlying bindings on the factory and listener sides. You'll want to explicitly validate the TChannel shape parameter against the shapes that your composite duplex supports before delegating.
- Override BuildChannelFactory and BuildChannelListener to delegate down to the underlying bindings on the factory and listener sides. You need some way of distinguishing the addresses of the two sides. If each side has its own transport and protocol scheme, they'll resolve to separate base addresses on your service host and avoid a conflict. If the two sides have the same protocol scheme, then they'll pick up the same base address. The BindingContext has an explicit override mechanism that you can use for the address of the listener side.
- Override GetProperty to have a meaningful resolution order. GetProperty returns a single value. If you have a different collection of property settings on the listener and factory sides, you need to pick one to be the winner when both want to return a query result.
- Consider the impact of your shape changing on metadata and security. Underneath of your binding element, the channel stack is going to be forked into two connections. This is generally going to cause problems for anyone that assumes that the endpoint you receive messages from is the same as the endpoint you write messages to. That may break guarantees, such as the ISecurityCapabilities, of underlying channels. You need to explicitly correct the guarantees that are being advertised through GetProperty.
Next time: You Must Understand This
Comments
- Anonymous
September 05, 2006
In the previous articles about MEX endpoints, I always used the MetadataExchangeBindings class to create...