Click here to Skip to main content
11,479,486 members (42,326 online)
Click here to Skip to main content
Add your own
alternative version

Dynamic insertion of a client channel sink provider

, 10 Apr 2003 CPOL 47.2K 563 26
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.Collections;
using System.Runtime.Remoting;

namespace RemotingHelper {
	/// <summary>
	/// Summary description for RemotingHelper.
	/// This code was hi-jacked from Ingo Rammers's website
	/// http://www.ingorammer.com
	/// and modified by me
	/// </summary>

	public class RemotingUtil {
		static bool _isInit;
		static IDictionary _wellKnownTypes;

		public static Object GetObject(Type type) {
			if (!_isInit)
				InitTypeCache();

			WellKnownClientTypeEntry entry = (WellKnownClientTypeEntry)_wellKnownTypes[type.FullName];

			if (entry == null)
				throw new RemotingException("Type not found!");

			String frmt = entry.ObjectUrl as String;
			if(frmt.EndsWith("soap"))
				frmt= "soap";
			else
				frmt = "binary";

			return RemotingServices.Connect(entry.ObjectType, entry.ObjectUrl, frmt);
		}

		static void InitTypeCache() {
			_isInit = true;
			_wellKnownTypes = new Hashtable();

			WellKnownClientTypeEntry[] Entries = RemotingConfiguration.GetRegisteredWellKnownClientTypes();

			foreach(WellKnownClientTypeEntry entry in Entries) {
				if(entry.ObjectType == null)
					throw new Exception("A configured type could not be found. Please check spelling");

				_wellKnownTypes.Add(entry.ObjectType.FullName, entry);
			}
		}
	}

}

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 | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 11 Apr 2003
Article Copyright 2003 by Wytek Szymanski
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid