Click here to Skip to main content
13,248,107 members (37,693 online)
Click here to Skip to main content


26 bookmarked
Posted 10 Apr 2003

Dynamic insertion of a client channel sink provider

, 10 Apr 2003
Workaround to specify a desired channel for connecting to a remote object
Remoting Helper Solution
Remoting Helper Solution.suo
using System;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;

namespace TestLibrary {

	using InterfaceLibrary;

    public class TestObject : MarshalByRefObject, ITestObject  {
		public delegate String Delegate(String s);

		public TestObject() : this(String.Empty) {
		public TestObject(String name) {
			Console.WriteLine("{0}: Object Constructor called.", name); = name;
			counter = 0;
		String name = "TestObject";
        static public int counter = 0;
        public String Ping()
            Console.WriteLine("\nEntering Ping() on {0}, counter {1}", name, counter);
            return String.Format("Returning from Ping() on {0}, counter {1}", name, counter);            

        [OneWay] public void OneWayMethod(String s) {
            Console.WriteLine("\nEntering OneWayMethod() on {0} with parameter {1}", name, s);
        public void RegularMethod(String s) {
             Console.WriteLine("\nEntering RegularMethod() on {0} with parameter {1}", name, s);

        public String AsyncMethod(String s) {
            Console.WriteLine("\nEntering AsyncMethod() on {0} with parameter {1}", name, s);
            return String.Format("Returning from AsyncMethod() with {0} on {1}", s, name);

		public String CallMe(ICallbackObject cb) {
            Console.WriteLine("\nEntering CallMe() on {0}", name);
            Console.WriteLine("{0}: Trying a callback...", name);
            String result = cb.Callback(String.Format("Calling back from CallMe() on {0} ...", name));
			Console.WriteLine("Callback result: {0}", result);

            return String.Format("Returning from CallMe() on {0}", name);

		public String CallMeOneWay(ICallbackObject cb) {
            Console.WriteLine("\nEntering CallMeOneWay() on {0}", name);
			Console.WriteLine("{0}: Trying a one way callback ...", name);

			cb.OneWayCallback(String.Format("Calling back from CallMeOneWay() on {0} ...", name));

			return String.Format("Returning from CallMeOneWay() on {0}", name);

		public String CallMeAsync(ICallbackObject cb) {
            Console.WriteLine("\nEntering CallMeAsync() on {0}", name);
			Console.WriteLine("{0}: Trying async callback ...", name);

			Delegate async = new Delegate(cb.AsyncCallback);
			IAsyncResult asyncResult = async.BeginInvoke(String.Format("Calling back from CallMeAsync() on {0} ...", name), null, null);
			//Wait for the call to complete

			String result = async.EndInvoke(asyncResult);

			Console.WriteLine("Callback result: {0}", result);
			return String.Format("Returning from CallMeAsync() on {0}", name);

	public class KnossosObject : TestObject, IKnossosObject {
		public KnossosObject() : base("knossos") { }
	public class ZakrosObject : TestObject, IZakrosObject {
		public ZakrosObject() : base("zakros") { }

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
Web01 | 2.8.171114.1 | Last Updated 11 Apr 2003
Article Copyright 2003 by Wytek Szymanski
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid