使用.Net Remoting有没有办法在可以访问之前修改远程对象?

时间:2016-10-25 07:55:15

标签: c# .net-remoting

我有两个流程通过.Net remoting,流程AB进行通信。我希望该流程A修改List,然后将其发送到流程B

我有以下代码(两个进程共享相同的代码):

namespace MyProcess
{
    class Program
    {       
        static void Main(string[] args)
        {
            //Process A modifies List
            if(process A){
                changeList();
                createOutputList();
            }
            //Process B gets the List 
            if(process B){
                OutputListObject op = retrieveOutputList();
                op.getList();
            }           
            Console.ReadKey();
        }

        void changeList()
        {
            //Some modification
        }

        OutputListObject retrieveOutput()
        {
            TcpChannel channel = new TcpChannel();
            ChannelServices.RegisterChannel(channel, false);

            OutputListObject op = (OutputListObject)Activator.GetObject(
                typeof(OutputListObject),
                "tcp://localhost:10001/MyRemoteOperator");

            return op;
        }

        void createOutput()
        {
            TcpChannel channel = new TcpChannel(10001);
            ChannelServices.RegisterChannel(channel, false);

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(OutputListObject),
                "OutputList",
                WellKnownObjectMode.Singleton);
        }

    }

    public class OutputListObject : MarshalByRefObject
    {
        public List<String> getList()
        {
            //return the modified list by Process A
        }
    }
}

提前致谢!

0 个答案:

没有答案