Share via


Channel Properties [Sowmy Srinivasan]

As Doug indicated I was going to post my deranged .NET Remoting ramblings in my blog. But then John had created this cool blog especially for our Remoting users. So I'll start putting my Remoting posts here.

One of the most frequent problems users run into is the lack of strong types to set channel properties. Today the user has to pass these properties in a dictionary. An example of this can be found here. One of the reasons this was done this way is due to the fact the set of properties are meant for the entire sink chain containing a variety of (both built-in and custom) sinks. The problem here is that you can misspell a property in the dictionary, and the Remoting code assumes that you intended it for a custom sink. This is great for extensibility, but makes it easy to misconfigure your channel.

To help with this, I created simple helper classes that provide a strongly typed façade for the properties of the built-in channels (.Net 2.0). It can be used as shown below:

ServerFormatterProperties formatterProperties = new ServerFormatterProperties();

formatterProperties.TypeFilterLevel = TypeFilterLevel.Full;

TcpServerChannelProperties channelProperties = new TcpServerChannelProperties();

channelProperties.Name = "TcpServer";

channelProperties.Port = 8000;

channelProperties.ExclusiveAddressUse = true;

TcpServerChannel serverChannel = new TcpServerChannel(channelProperties, new BinaryServerFormatterSinkProvider(formatterProperties, null));

ChannelServices.RegisterChannel(serverChannel, true/*ensureSecurity*/);

ChannelServices.RegisterChannel(new TcpClientChannel(), true/*ensureSecurity*/);

The list of properties the built-in channels support can be found here.

My sample has one properties-class for each of the six built-in channels and two properties-class for setting formatter properties (Binary and Soap Formatter sinks). The properties class implements IDictionary and hence can be used as a weakly typed property bag for custom properties.

Update: Modified the attachement to fix a typo in PropertyHelpers.ServerProtectionLevel

RemotingChannelProperties.cs