static void Main()
    {
        ChannelServices.RegisterChannel(new TcpChannel(8085));
        RemotingConfiguration.RegisterActivatedServiceType(
            typeof(MyServerImpl));

// <Snippet1>
// <Snippet2>

        // Check whether the 'MyServerImpl' object is allowed for
        // activation or not.
        if (RemotingConfiguration.IsActivationAllowed(typeof(MyServerImpl)))
        {
            // Get the registered activated service types .
            ActivatedServiceTypeEntry[] myActivatedServiceEntries =
                RemotingConfiguration.GetRegisteredActivatedServiceTypes();
            Console.WriteLine("The Length of the registered activated service"
                              + " type array is " + myActivatedServiceEntries.Length);
            Console.WriteLine("The Object type is:"
                              + myActivatedServiceEntries[0].ObjectType);
        }

// </Snippet2>
// </Snippet1>

        Console.WriteLine("Press enter to stop this process.");
        Console.ReadLine();
    }
Example #2
0
        private void SetupService()
        {
            if (AutoOfferPort)
            {
                for (Port = 2080; Port < 60000; Port++)
                {
                    try
                    {
                        BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                        serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                        BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                        IDictionary props = new Hashtable();

                        props["port"] = Port;
                        Channel       = new TcpChannel(props, clientProv, serverProv);
                        break;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Error finding free port");
                    }
                }
            }
            else
            {
                try
                {
                    BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                    serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                    BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                    IDictionary props = new Hashtable();

                    props["port"] = Port;
                    Channel       = new TcpChannel(props, clientProv, serverProv);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error opening TCP channel");
                    ServerServices.AddMessage(1, "Cannot use port " + Port);
                    return;
                }
            }

            ChannelServices.RegisterChannel(Channel, false);
            // Register ServerServices
            if (!RemotingConfiguration.IsActivationAllowed(typeof(ServerServices)))
            {
                RemotingConfiguration.RegisterActivatedServiceType(typeof(ServerServices));
            }
            // Register MasterServer
            if (!RemotingConfiguration.IsActivationAllowed(typeof(MasterServer)))
            {
                RemotingConfiguration.RegisterActivatedServiceType(typeof(MasterServer));
            }
            ServerServices.AddMessage(0, "Server running at port " + Port);
        }
Example #3
0
        public IConstructionReturnMessage Activate(IConstructionCallMessage msg)
        {
            if (!RemotingConfiguration.IsActivationAllowed(msg.ActivationType))
            {
                throw new RemotingException("The type " + msg.ActivationTypeName + " is not allowed to be client activated");
            }
            object[] activationAttributes = new object[]
            {
                new RemoteActivationAttribute(msg.ContextProperties)
            };
            MarshalByRefObject obj          = (MarshalByRefObject)Activator.CreateInstance(msg.ActivationType, msg.Args, activationAttributes);
            ObjRef             resultObject = RemotingServices.Marshal(obj);

            return(new ConstructionResponse(resultObject, null, msg));
        }
Example #4
0
        public IConstructionReturnMessage Activate(IConstructionCallMessage msg)
        {
            if (!RemotingConfiguration.IsActivationAllowed(msg.ActivationType))
            {
                throw new RemotingException("The type " + msg.ActivationTypeName + " is not allowed to be client activated");
            }

            object[]           activationAttributes = new object[] { new RemoteActivationAttribute(msg.ContextProperties) };
            MarshalByRefObject newObject            = (MarshalByRefObject)Activator.CreateInstance(msg.ActivationType, msg.Args, activationAttributes);

            // The activator must return a ConstructionResponse with an ObjRef as return value.
            // It avoids the automatic creation of a proxy in the client.

            ObjRef objref = RemotingServices.Marshal(newObject);

            return(new ConstructionResponse(objref, null, msg));
        }