Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Dynamic insertion of a client channel sink provider

, 10 Apr 2003 CPOL
Workaround to specify a desired channel for connecting to a remote object
abstract_client_formatter_src.zip
Remoting Helper Solution
InterfaceLibrary
App.ico
InterfaceLibrary.csproj.user
Remoting Helper Solution.suo
RemotingClient
App.ico
RemotingClient.csproj.user
RemotingHelper
RemotingHelper.csproj.user
RemotingServer
App.ico
RemotingServer.csproj.user
TestLibrary
TestLibrary.csproj.user
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);
			this.name = name;
			counter = 0;
		}
		String name = "TestObject";
        static public int counter = 0;
        public String Ping()
        {
            counter++;
            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
			//
			asyncResult.AsyncWaitHandle.WaitOne();

			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.

License

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

Share

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.

| Advertise | Privacy | Mobile
Web04 | 2.8.141029.1 | Last Updated 11 Apr 2003
Article Copyright 2003 by Wytek Szymanski
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid