using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Configuration;
using System.Runtime.Serialization.Formatters;

namespace Core.Mes.ServerListener
{

    public class RemotingGate
    {
        public RemotingGate()
        {
            StartServer();
        }

        public void StartServer()
        {
            try
            {
                string ServerURL = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["RemoteServerUrl"].Value.ToString().Trim();

                UriBuilder ub = new UriBuilder(ServerURL);

                RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
                ChannelServices.RegisterChannel(new TcpChannel(ub.Port - 2), false);
            }
            catch (Exception ex)
            {
                throw new  Exception(ex.Message, ex);
            }
        }

    }
}

