I am accessing an object remotely using a Transparent Proxy.
The object, named TaskSchedulerServiceManager
(which implements MarshalByRefObject
), has a method on it named GetMachineName
, which should simply return the NetBios name assigned to the machine the actual object is running on.
public class TaskSchedulerServiceManager : MarshalByRefObject
{ public string GetMachineName()
{
log.Write(log.Level.Debug, "GetMachineName()", eventSource);
return Environment.MachineName.ToUpper(); // <- line that throws exception
}
}
The TransparentProxy is instantiated using System.Activator.GetObject()
in the following code:
private static TaskSchedulerServiceManager
GetServerManager(TaskSchedulerServer svr)
{
svr.RegisterChannel(); // see below
var url = "tcp://" + svr.ServerName + ":" +
svr.TcpPort + "/" + svr.ManagerUri;
return (TaskSchedulerServiceManager)Activator.GetObject(
typeof(TaskSchedulerServiceManager), url);
}
public void RegisterChannel()
{
UnRegisterChannel();
IDictionary propBag = new Hashtable();
propBag["port"] = TcpPort;
propBag["name"] = KeyID;
propBag["connectionTimeout"] = 1000;
if (SecurityMode == RemSecMode.Identify)
{
propBag["secure"] = true;
propBag["tokenImpersonationLevel"] =
TokenImpersonationLevel.Identification;
propBag["useDefaultCredentials"] = true;
}
if (ChannelServices.RegisteredChannels.Any(
chn => chn.ChannelName == KeyID &&
chn is TcpClientChannel)) return;
// ------------------------------------------
tcpCh = new TcpClientChannel(propBag, null);
if (!ChannelServices.RegisteredChannels.Contains(tcpCh))
ChannelServices.RegisterChannel(tcpCh, false);
}
Now in my client code I am trying to clal GetMachineName on the transparentProxy as shown in the first snippet above. When I do a System.Runtime.Remoting.RemotingException
is thrown:
System.Runtime.Remoting.RemotingException: 'The method 'GetMachineName' was not found on the interface/type 'CoP.Enterprise.Scheduler.TaskSchedulerServiceManager, CoP.Enterprise.TaskScheduler, Version=0.31.200.31000, Culture=neutral, PublicKeyToken=null'.'
Even though intellisense shopws that the method exists on the object and the compiler does not throw a compile error.
What is up with this?