首页 新闻 会员 周边 捐助

由于安全限制,无法访问类型 System.Runtime.Remoting.ObjRef

0
悬赏园豆:5 [已解决问题] 解决于 2009-08-20 16:00

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".

要求是按引用封送的,哪位高手来帮忙解决一下.

451114258的主页 451114258 | 初学一级 | 园豆:1
提问于:2009-08-20 12:30
< >
分享
最佳答案
0
收获园豆:5
Kinglee | 老鸟四级 |园豆:3158 | 2009-08-20 14:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册