using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Security.Permissions;
namespace ServerClassRef
{
public class ForwardMe : MarshalByRefObject
{
public void CallMe()
{
Console.WriteLine("CallMe was executed in: " +
Process.GetCurrentProcess().ProcessName.ToString());
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Permissions;
namespace ServerClassRef
{
public class HelloServer : MarshalByRefObject
{
public void HelloMethod(ForwardMe obj)
{
obj.CallMe();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Security.Permissions;
namespace Server
{
public class Program
{
public static void Main(string[] args)
{
TcpChannel chan = new TcpChannel(8085);
ChannelServices.RegisterChannel(chan,true );
RemotingConfiguration.RegisterWellKnownServiceType(
Type.GetType("ServerClassRef.HelloServer, ServerClassRef"),
"RemoteTestRef",
WellKnownObjectMode.Singleton);
Console.WriteLine("Press <ENTER> to exit...");
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using ServerClassRef;
using System.Collections;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Serialization.Formatters;
using System.Security.Permissions;
namespace Client
{
public class Program
{
public static void Main(string[] args)
{
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan, true);
ForwardMe objForwardMe = new ForwardMe();
HelloServer objHelloServer;
objHelloServer = (HelloServer)Activator.GetObject(
typeof(HelloServer),
"tcp://localhost:8085/RemoteTestRef");
if (objHelloServer == null)
Console.WriteLine("Could not locate server");
else
{
objHelloServer.HelloMethod(objForwardMe);
}
Console.WriteLine("Press <ENTER> to exit...");
Console.ReadLine();
}
}
}
这一句objHelloServer.HelloMethod(objForwardMe);
老提示错误:"由于安全限制,无法访问类型 System.Runtime.Remoting.ObjRef".
要求是按引用封送的,哪位高手来帮忙解决一下.