Configuring the ChannelManager

I’m trying to keep configuration to a minimum. Let’s look at an example:

<object id="MyService" type="WCFChannelManager.ChannelManagerFactoryObject">
	<property name="ChannelType" expression="T(WCFChannelManagerTests.IService)"/>
	<property name="EndpointConfigurationName" value="MyEndpointName"/>
</object>

This is probably what you’ll need the most. You define the ChannelType, that is the interface exposed by the service you want to consume, and the EndpointConfigurationName, which is the name of the endpoint in the system.servicemodel section of your app/web.config. And that’s it. The behaviour of the channel in this case is that a new channel will be created for every operation you want to execute.

<object id="MyService" type="WCFChannelManager.ChannelManagerFactoryObject">
	<property name="ChannelType" expression="T(WCFChannelManagerTests.IService)"/>
	<property name="EndpointConfigurationName" value="MyEndpointName"/>
	<property name="ChannelManagementMode" value="Recycle"/>
</object>

If you want channels to be reused, you can specify this by changing the value of the ‘ChannelManagementMode’. There are two predefined values you can use here, Recycle and ThrowAway. ThrowAway being the default. Not sure about these names though :-).

<object id="OneTimeUseChannel" type="WCFChannelManager.SingleActionChannelManager&lt;WCFChannelManagerTests.IService>"/>
<object id="MyService" type="WCFChannelManager.ChannelManagerFactoryObject">
	<property name="ChannelType" expression="T(WCFChannelManagerTests.IService)"/>
	<property name="EndpointConfigurationName" value="MyEndpointName"/>
	<property name="ProductTemplate">
	<object>
		<property name="ChannelManager" ref="OneTimeUseChannel"/> 
	</object>
	</property>
</object>

If one of the default ways to manage the lifecycle of a channel is not what you want or need you can create your own and specify it in the ProductTemplate property of the ChannelManagerFactoryObject. The example above shows how you can do this, in this case it would result in the same default behaviour you get in the first xml configuration I showed in the beginning of my post.

If you even want to customize the way a channel is retrieved, an action is executed on it and then handed back to the channel lifecycle manager, you can subclass ChannelActionWrapper and specify that type in the ChannelActionWrapperType property of the ChannelManagerFactoryObject. This is illustrated below:

<object id="MyService" type="WCFChannelManager.ChannelManagerFactoryObject">
	<property name="ChannelActionWrapperType" expression="T(WCFChannelManagerTests.MockChannelManager)"/>
	<property name="EndpointConfigurationName" value="MyEndpointName"/>
</object>
public class MockChannelManager
	: ChannelActionWrapper<IService>
{
	public MockChannelManager()
	: base(null)
	{
 
	}
	public override IService  GetChannelToWorkWith()
	{
		return new Service();
	}
 
 
	public object ExecuteOperation(MethodInfo info, object[] parameters)
	{
		return this.ExecuteInChannel(info, parameters);
	}
}

The ChannelType will now be retrieved from your subclass so you don’t need to specify the ChannelType.

And that’s all I have for you now.

Series:

Leave a Reply

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