Click here to Skip to main content
12,893,816 members (55,220 online)
Click here to Skip to main content


24 bookmarked
Posted 17 May 2003

The case for a channel-schema concept

, 17 May 2003 CPOL
An article about .NET remoting channel schemas
// Stephen Toub
// SecureClientChannelSinkProvider.cs

using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;

namespace MsdnMag.Remoting
	/// <summary>Used to create a secure client channel sink.</summary>
	public class SecureClientChannelSinkProvider : IClientChannelSinkProvider
		#region Member Variables
		/// <summary>Reference to the next sink provider in the provider chain.</summary>
		private IClientChannelSinkProvider _next = null;
		/// <summary>The name of the symmetric algorithm to use.</summary>
		private string _algorithm = "DES";
		/// <summary>Whether OAEP padding should be used.</summary>
		private bool _oaep = false;
		/// <summary>The maximum number of times we should attempt to process a message.</summary>
		private int _maxAttempts = 2; // includes first try and one retry

		#region Construction
		/// <summary>Initialize the sink provider.</summary>
		public SecureClientChannelSinkProvider()
			// uses defaults

		/// <summary>Initialize the sink provider.</summary>
		/// <param name="properties">Parameters specified in the config file.</param>
		/// <param name="providerData">Sink provider data.</param>
		public SecureClientChannelSinkProvider(IDictionary properties, ICollection providerData) 
			// Read in web.config parameters
			foreach (DictionaryEntry entry in properties)
				switch ((String)entry.Key)
					case "algorithm": 
						_algorithm = (string)entry.Value; 

					case "oaep": 
						_oaep = bool.Parse((string)entry.Value); 

					case "maxRetries": 
						_maxAttempts = Convert.ToInt32((string)entry.Value); 
						if (_maxAttempts < 1) throw new ArgumentException("Maximum number of attempts must be at least 1.", "maxAttempts");
						_maxAttempts++; // number of attempts should include the first try

						throw new ArgumentException("Invalid configuration entry: " + (String)entry.Key);

		#region Sink Creation
		/// <summary>Creates a sink chain.</summary>
		/// <param name="channel">Channel for which the current sink chain is being constructed.</param>
		/// <param name="url">The URL of the object to connect to.</param>
		/// <param name="remoteChannelData">A channel data object describing a channel on the remote server.</param>
		/// <returns>A reference to the new sink, or null if it could not be created.</returns>
		public System.Runtime.Remoting.Channels.IClientChannelSink CreateSink(System.Runtime.Remoting.Channels.IChannelSender channel, string url, object remoteChannelData)
			IClientChannelSink nextSink = null;

			if (_next != null)
				// Call CreateSink on the next sink provier in the chain.  This will return
				// to us the actual next sink object.  If the next sink is null, uh oh!
				if ((nextSink = _next.CreateSink(channel, url, remoteChannelData)) == null) return null;

			// Create this sink, passing to it the previous sink in the chain so that it knows
			// to whom messages should be passed.
			return new SecureClientChannelSink(nextSink, _algorithm, _oaep, _maxAttempts);

		/// <summary>Gets or sets the next sink provider in the channel sink provider chain.</summary>
		public System.Runtime.Remoting.Channels.IClientChannelSinkProvider Next
			get { return _next; }
			set { _next = value; }

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Wytek Szymanski
Web Developer
United States United States
I am a consultant, trainer, software archtect/engineer, since the early 1980s, working in the greater area of Boston, MA, USA.

My work comprises the entire spectrum of software, shrink-wrapped applications, IT client-server, systems and protocol related work, compilers and operating systems, and more ....

I am currently focused on platform development for distributed computing in service oriented data centers.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 18 May 2003
Article Copyright 2003 by Wytek Szymanski
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid