Click here to Skip to main content
13,143,774 members (29,397 online)
Click here to Skip to main content

Stats

50.2K views
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
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;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;

using RemotingHelper;
using InterfaceLibrary;



namespace RemotingClient {

	public class CallbackObject : MarshalByRefObject, ICallbackObject {
		public String Callback(String msg) {
			Console.WriteLine("Callback received!");
			return "Return from CallbackObject.Callback";
		}
		[OneWay] public void OneWayCallback(String msg) {
			Console.WriteLine("OneWayCallback received!");
			Console.WriteLine(msg);
		}
		public String AsyncCallback(String msg) {
			Console.WriteLine("AsyncCallback received!");
			Console.WriteLine(msg);
			return "Return from CallbackObject.AsyncCallback.";
		}
	}

	delegate String Delegate(String s);

	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1 {
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)	{

			try {

				RemotingConfiguration.Configure(@"..\..\RemotingClient.exe.config");

				IKnossosObject objKnossos = (IKnossosObject)RemotingUtil.GetObject(typeof(IKnossosObject));
				IZakrosObject objZakros = (IZakrosObject)RemotingUtil.GetObject(typeof(IZakrosObject));	
	
				Console.WriteLine("Communicating with Knossos");
				Test(objKnossos);
				TestCallback(objKnossos);

				Console.WriteLine();

				Console.WriteLine("Communicating with Zakros");
				Test(objZakros);
				TestCallback(objZakros);


			} catch(Exception e) {
				Console.WriteLine(e);
			}

			Console.WriteLine("Press ENTER to quit...");
			Console.ReadLine();
		}


		static void TestCallback(ITestObject obj) {
			int sync = 2;
			int oneway = 2;
			int async = 2;

			CallbackObject callback = new CallbackObject();

			if(sync > 0) {
				Console.WriteLine("Method with Sync Callback from Server");
				while(sync-- > 0) 
					Console.WriteLine(obj.CallMe(callback));
			}
			if(async > 0) {
				Console.WriteLine("Method with Async Callback from Server");
				while(async-- > 0) 
					Console.WriteLine(obj.CallMeAsync(callback));
			}
			if(oneway > 0) {
				Console.WriteLine("Method with OneWay Callback from Server");
				while(oneway-- > 0) 
					Console.WriteLine(obj.CallMeOneWay(callback));
			}

		}
		static void Test(ITestObject obj) {

			int ping = 3;
			int regular = 3;
			int asyncway = 3;
			int oneway = 3;


			if(ping > 0) {
				Console.WriteLine("Calling Ping()");
				while(ping-- > 0)
					Console.WriteLine(obj.Ping());
			}

			if(regular > 0) {
				Console.WriteLine();
				Console.WriteLine("Calling RegularMethod()");
				while(regular-- > 0) {
					obj.RegularMethod(String.Format("param {0}", regular));
				}
			}

			if(oneway > 0) {
				Console.WriteLine();
				Console.WriteLine("Calling OneWayMethod()");
				while(oneway-- > 0)
					obj.OneWayMethod(String.Format("param {0}", oneway));
			}

			if(asyncway > 0) {
				Console.WriteLine();
				Console.WriteLine("Calling AsyncMethod()");
				while(asyncway-- > 0) {
					Delegate async = new Delegate(obj.AsyncMethod);
					IAsyncResult result = async.BeginInvoke(String.Format("param {0}", asyncway), null, null);
					//
					//Wait for the call to complete
					//
					result.AsyncWaitHandle.WaitOne();
					Console.WriteLine(async.EndInvoke(result));
				}
			}

			Console.WriteLine();
		}
	}
}

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.

You may also be interested in...

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