Presenting a Generic RemotingHelper

Last couple of months i’ve been experimenting with Remoting. Here is a class that helps a client to acquire proxies to an endpoint served by the requested well-known object:

public static class RemotingHelper
{
 static RemotingHelper()
 {
  RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
 }

 private static object GetService(string fullName)
 {
  WellKnownClientTypeEntry[] wellKnownClientTypeEntries = RemotingConfiguration.GetRegisteredWellKnownClientTypes();
  foreach (WellKnownClientTypeEntry welknownClientTypeEntry in wellKnownClientTypeEntries)
  {
   if (welknownClientTypeEntry.ObjectType.FullName == fullName)
   {
    return Activator.GetObject(welknownClientTypeEntry.ObjectType, welknownClientTypeEntry.ObjectUrl);
   }
  }

  throw new ArgumentException(fullName + " is not a wellKnownClientType.");
 }

 public static T GetService<t>()
 {
   return (T) RemotingHelper.GetService(typeof(T).FullName);
 }
}

Getting a proxy is as easy as (Presuming that you’ve configured the system.runtime.remoting in your App.config):

IContract contract = RemotingHelper.GetService<icontract>();
  1. Tim,

    Thank you so much for response…

    I really appreciated it… It is good to know that individuals look at what is going on, and care about others.

    I just wanted to say thank you.

    Kenn

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>