private static void ConfigureRemoting(RemotingXmlConfigFileData configData, bool ensureSecurity)
 {
     try
     {
         string applicationName = configData.ApplicationName;
         if (applicationName != null)
         {
             ApplicationName = applicationName;
         }
         if (configData.CustomErrors != null)
         {
             _errorMode = configData.CustomErrors.Mode;
         }
         ConfigureChannels(configData, ensureSecurity);
         if (configData.Lifetime != null)
         {
             if (configData.Lifetime.IsLeaseTimeSet)
             {
                 LifetimeServices.LeaseTime = configData.Lifetime.LeaseTime;
             }
             if (configData.Lifetime.IsRenewOnCallTimeSet)
             {
                 LifetimeServices.RenewOnCallTime = configData.Lifetime.RenewOnCallTime;
             }
             if (configData.Lifetime.IsSponsorshipTimeoutSet)
             {
                 LifetimeServices.SponsorshipTimeout = configData.Lifetime.SponsorshipTimeout;
             }
             if (configData.Lifetime.IsLeaseManagerPollTimeSet)
             {
                 LifetimeServices.LeaseManagerPollTime = configData.Lifetime.LeaseManagerPollTime;
             }
         }
         _bUrlObjRefMode = configData.UrlObjRefMode;
         Info.StoreRemoteAppEntries(configData);
         Info.StoreActivatedExports(configData);
         Info.StoreInteropEntries(configData);
         Info.StoreWellKnownExports(configData);
         if (configData.ServerActivatedEntries.Count > 0)
         {
             ActivationServices.StartListeningForRemoteRequests();
         }
     }
     catch (Exception exception)
     {
         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_ConfigurationFailure"), new object[] { exception }));
     }
 }
 private static void ConfigureRemoting(RemotingXmlConfigFileData configData, bool ensureSecurity)
 {
     try
     {
         string applicationName = configData.ApplicationName;
         if (applicationName != null)
         {
             ApplicationName = applicationName;
         }
         if (configData.CustomErrors != null)
         {
             _errorMode = configData.CustomErrors.Mode;
         }
         ConfigureChannels(configData, ensureSecurity);
         if (configData.Lifetime != null)
         {
             if (configData.Lifetime.IsLeaseTimeSet)
             {
                 LifetimeServices.LeaseTime = configData.Lifetime.LeaseTime;
             }
             if (configData.Lifetime.IsRenewOnCallTimeSet)
             {
                 LifetimeServices.RenewOnCallTime = configData.Lifetime.RenewOnCallTime;
             }
             if (configData.Lifetime.IsSponsorshipTimeoutSet)
             {
                 LifetimeServices.SponsorshipTimeout = configData.Lifetime.SponsorshipTimeout;
             }
             if (configData.Lifetime.IsLeaseManagerPollTimeSet)
             {
                 LifetimeServices.LeaseManagerPollTime = configData.Lifetime.LeaseManagerPollTime;
             }
         }
         _bUrlObjRefMode = configData.UrlObjRefMode;
         Info.StoreRemoteAppEntries(configData);
         Info.StoreActivatedExports(configData);
         Info.StoreInteropEntries(configData);
         Info.StoreWellKnownExports(configData);
         if (configData.ServerActivatedEntries.Count > 0)
         {
             ActivationServices.StartListeningForRemoteRequests();
         }
     }
     catch (Exception exception)
     {
         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_ConfigurationFailure"), new object[] { exception }));
     }
 }
Ejemplo n.º 3
0
        internal static void SetCustomErrorsMode(string mode)
        {
            if (mode == null)
            {
                throw new RemotingException("mode attribute is required");
            }

            // the mode is case insensitive
            string m = mode.ToLower();

            if (m != "on" && m != "off" && m != "remoteonly")
            {
                throw new RemotingException("Invalid custom error mode: " + mode);
            }

            _errorMode = (CustomErrorsModes)Enum.Parse(typeof(CustomErrorsModes), m, true);
        }
Ejemplo n.º 4
0
        [System.Security.SecurityCritical]  // auto-generated
        private static void ConfigureRemoting(RemotingXmlConfigFileData configData, bool ensureSecurity)
        {
            try
            {
                String appName = configData.ApplicationName;
                if (appName != null)
                    ApplicationName = appName;
                
                if (configData.CustomErrors != null)
                    _errorMode = configData.CustomErrors.Mode;

                // configure channels
                ConfigureChannels(configData, ensureSecurity);
            
                // configure lifetime
                if (configData.Lifetime != null)
                {
                    if (configData.Lifetime.IsLeaseTimeSet)
                        LifetimeServices.LeaseTime = configData.Lifetime.LeaseTime;
                    if (configData.Lifetime.IsRenewOnCallTimeSet)
                        LifetimeServices.RenewOnCallTime = configData.Lifetime.RenewOnCallTime;
                    if (configData.Lifetime.IsSponsorshipTimeoutSet)    
                        LifetimeServices.SponsorshipTimeout = configData.Lifetime.SponsorshipTimeout;
                    if (configData.Lifetime.IsLeaseManagerPollTimeSet)
                        LifetimeServices.LeaseManagerPollTime = configData.Lifetime.LeaseManagerPollTime;
                }

                _bUrlObjRefMode = configData.UrlObjRefMode;

                // configure other entries
                Info.StoreRemoteAppEntries(configData);
                Info.StoreActivatedExports(configData);
                Info.StoreInteropEntries(configData);
                Info.StoreWellKnownExports(configData);

                // start up activation listener if there are any activated objects exposed
                if (configData.ServerActivatedEntries.Count > 0)
                    ActivationServices.StartListeningForRemoteRequests();                
            }
            catch (Exception e)
            {
                throw new RemotingException(
                    String.Format(
                        CultureInfo.CurrentCulture, Environment.GetResourceString(
                            "Remoting_Config_ConfigurationFailure"),                        
                        e));
            }
        } // ConfigureRemoting
 internal CustomErrorsEntry(CustomErrorsModes mode)
 {
     this.Mode = mode;
 }
Ejemplo n.º 6
0
 internal CustomErrorsEntry(CustomErrorsModes mode)
 {
     this.Mode = mode;
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            try
            {
                bool              secure        = false;
                int               port          = 12345;
                string            ipc           = string.Empty;
                bool              bind_any      = false;
                bool              showhelp      = false;
                TypeFilterLevel   typefilter    = TypeFilterLevel.Low;
                CustomErrorsModes custom_errors = CustomErrorsModes.Off;
                string            name          = "RemotingServer";
                bool              disable_transparent_proxy_fix = false;

                OptionSet p = new OptionSet()
                {
                    { "s|secure", "Enable secure mode", v => secure = v != null },
                    { "p|port=", "Specify the local TCP port to listen on", v => port = int.Parse(v) },
                    { "t|typefilter=", "Specify the type filter level (low,full), default low",
                      v => typefilter = (TypeFilterLevel)Enum.Parse(typeof(TypeFilterLevel), v, true) },
                    { "i|ipc=", "Specify listening pipe name for IPC channel", v => ipc = v },
                    { "e|error=", "Set custom error mode (On, Off, RemoteOnly) (don't show full errors in remote calls)",
                      v => custom_errors = (CustomErrorsModes)Enum.Parse(typeof(CustomErrorsModes), v, true) },
                    { "n|name=", "Set the remoting class name", v => name = v },
                    { "d", "Enable the 'AllowTransparentProxyMessage' setting fix.", v => disable_transparent_proxy_fix = v != null },
                    { "a|any", "When using TCP bind to any interface, otherwise only to localhost", v => bind_any = v != null },
                    { "h|?|help", v => showhelp = v != null },
                };

                Console.WriteLine("Example .NET Remoting Server");
                Console.WriteLine("Copyright (c) James Forshaw 2014");
                Console.WriteLine(".NET Version: {0}", Environment.Version);
                p.Parse(args);
                if (showhelp)
                {
                    p.WriteOptionDescriptions(Console.Out);
                }
                else
                {
                    SetAllowTransparentProxy(!disable_transparent_proxy_fix);
                    RemotingConfiguration.CustomErrorsMode = custom_errors;

                    Console.WriteLine("Enable Transparent Proxy Fix: {0}", disable_transparent_proxy_fix);
                    Console.WriteLine("Custom Errors Mode: {0}", custom_errors);
                    Console.WriteLine("Type Filter Level: {0}", typefilter);

                    Trace.Listeners.Add(new ConsoleTraceListener(true));

                    IChannel    chan;
                    IDictionary properties = new Hashtable();

                    BinaryServerFormatterSinkProvider serverSinkProvider = new BinaryServerFormatterSinkProvider();
                    serverSinkProvider.TypeFilterLevel = typefilter;

                    if (!string.IsNullOrEmpty(ipc))
                    {
                        properties["portName"]        = ipc;
                        properties["authorizedGroup"] = "Everyone";

                        chan = new IpcChannel(properties, new BinaryClientFormatterSinkProvider(), serverSinkProvider);
                    }
                    else
                    {
                        Console.WriteLine("Any Bind: {0}", bind_any);
                        properties["port"] = port;
                        properties["rejectRemoteRequests"] = !bind_any;
                        chan = new TcpChannel(properties, new BinaryClientFormatterSinkProvider(), serverSinkProvider);
                    }

                    ChannelServices.RegisterChannel(chan, secure);    //register channel

                    RemotingConfiguration.RegisterWellKnownServiceType(
                        typeof(RemoteType),
                        name,
                        WellKnownObjectMode.Singleton);

                    bool isipc = chan is IpcChannel;

                    Console.WriteLine("Server Activated at {0}://{1}/{2}", isipc ? "ipc" : "tcp", isipc ? ipc : "HOST:" + port.ToString(), name);
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }