WCF ChannelManagement drop 3

A new version is available, with two modes of channel pooling.

The ‘FixedPool’ mode is based on the SimplePool which you can find in the Spring.Pooling library. Meaning that at any given time there can be a maximum of x amount of channels. Where x equals the SimplePool’s size. So if the size of your pool is 5 and you request a 6th channel while the previous 5 are still busy doing their business you’ll get a blocking thread until one of the previous five is returned to the pool. This is good for when you want to limit the connectivity to your server, but don’t forget that it will block the calling thread when you request more channels than there are available.

The other pool mode is ‘VariablePool’. This is a pool that grows and shrinks depending on the load. So if you request 6 channels you’ll get 6 channels which will be available for future requests when returned to the pool. Channels which are no longer usable will be removed and new ones will be created when needed.

I spend most of the time trying to find a good away around my dependency on ChannelFactory. Since that class has a method ‘CreateChannel’ which takes no arguments and the factory can be configured using the endpoint name in your system.servicemodel section. The interface which the class implements doesn’t have this. The classes which populate a channelfactory from the app.config are marked internal and so you can’t use them.

The only solution I found that worked pretty ok was a wrapper interface which exposes the CreateChannel method, it helped me to test the code without a channelfactory instance.

I did a lot of renaming in the codebase but on the consuming end not much has changed.

A ‘SingleAction’ operating channel is still the easiest to configure.

<object id=“MyService” type=“WCFChannelManager.ChannelManagerFactoryObject, Perponcher.WCFChannelManager”>
	<property name=“ChannelType” expression=“T(Server.IService1, Common)/>
	<property name=“EndpointConfigurationName” value=“MyEndpoint”/>
</object>

Creating a fixed pool is one extra line.

<object id=“MyService” type=“WCFChannelManager.ChannelManagerFactoryObject, Perponcher.WCFChannelManager”>
	<property name=“ChannelType” expression=“T(Server.IService1, Common)/>
	<property name=“EndpointConfigurationName” value=“MyEndpoint”/>
	<property name=“ChannelManagementMode” value=“FixedPool”/>
</object>

A variable pool means just another value as ChannelManagementMode.

<object id=“MyService” type=“WCFChannelManager.ChannelManagerFactoryObject, Perponcher.WCFChannelManager”>
	<property name=“ChannelType” expression=“T(Server.IService1, Common)/>
	<property name=“EndpointConfigurationName” value=“MyEndpoint”/>
	<property name=“ChannelManagementMode” value=“VariablePool”/>
</object>

If you want to use your own channel manager, you can use the ProductTemplate to hook everything up. The sample below illustrates this, here the variable pool is configured via the template instead of using the ChannelManagementMode property of the FactoryObject.

<object id="MyService" type="WCFChannelManager.ChannelManagerFactoryObject, Perponcher.WCFChannelManager">
	<property name="ChannelType" expression="T(Server.IService1, Common)"/>
	<property name="EndpointConfigurationName" value="MyEndpoint"/>
	<property name="ProductTemplate">
	<object>
		<property name="ChannelManager">
			<object type="WCFChannelManager.ChannelPoolManager&lt;Server.IService1>, Perponcher.WCFChannelManager">
				<constructor-arg value="MyEndpoint"/>
				<constructor-arg>
					<object type="WCFChannelManager.AutoSizePoolFactory, Perponcher.WCFChannelManager"/>
				</constructor-arg>
			</object>
		</property>
	</object>
	</property>
</object>

The same approach can be used to configure the channelfactory for i.e. passing credentials.

<object id="MyService" type="WCFChannelManager.ChannelManagerFactoryObject, Perponcher.WCFChannelManager">
	<property name="ChannelType" expression="T(Server.IService1, Common)"/>
	<property name="EndpointConfigurationName" value="MyEndpoint"/>
	<property name="ChannelManagementMode" value="VariablePool"/>
	<property name="ProductTemplate">
		<object>
			<property name="ChannelManager.ChannelFactory.Credentials.UserName.UserName" value="username"/>
			<property name="ChannelManager.ChannelFactory.Credentials.UserName.Password" value="password"/>
		</object>
	</property>
</object>

That’s it for now. Future additions will include:

  • setting the pool size of a fixed sized pool via the FactoryObject, for now the default of 5 is used
  • extend or add a new pool based on the SimplePool. At the moment closed or faulted channels are not removed from that implementation, meaning that when your 5 channels are closed the pool will raise an exception.

WCFChannelManager_drop3.zip (1.16 mb)

Series:

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.