We have developed a custom WCF channel which communicates via IBM Websphere MQ.
We have created a channel factory:
public class MqChannelFactory : ChannelFactoryBase<IRequestChannel>
Which returns instances of our channel:
public class MqRequestChannel : ChannelBase, IRequestChannel
Connecting to the IBM MQ queue manager is an expensive operation. Currently, we do this in Channel.OnOpen().
Following the guidelines for correct use of channels, we are callign ChannelFactory.CreateChannel() each time we require a channel, sending the message, then calling Channel.Close().
Our assumption was, that the ChannelFactory performed pooling of channels, so that when Channel.Close() was called, the channel was not actually closed but rather returned to the pool. But, everytime we call ChannelFactory.CreateChannel, a new channel is being instantiated, and when the request is sent, the expensive channel opening is performed.
So, the question: What is the best approach to prevent the channel being opened on every request?
Some of the options we are investigating:
Is there anyway through configuration to specify that channel pooling should take place? Should we be implementing our own channel pooling in our ChannelFactory?
Should we just keep our channel open for the life of the application, sending all requests through it?
Should we perform the expensive operation (connecting to the queue manager) in the channel factory , which we cache for the life of the application?