Exemple #1
0
        static void Main(string[] args)
        {
            TcpChannel channel = new TcpChannel(8086);

            ChannelServices.RegisterChannel(channel, false);
            ChannelDataStore data = (ChannelDataStore)channel.ChannelData;

            foreach (string uri in data.ChannelUris)
            {
                Console.WriteLine("The channel URI is {0}.", uri);
            }
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Server), "SuperChat", WellKnownObjectMode.Singleton);
            string[] urls = channel.GetUrlsForUri("SuperChat");
            if (urls.Length > 0)
            {
                string objectUrl = urls[0];
                string objectUri;
                string channelUri = channel.Parse(objectUrl, out objectUri);
                Console.WriteLine("The object URL is {0}.", objectUrl);
                Console.WriteLine("The object URI is {0}.", objectUri);
                Console.WriteLine("The channel URI is {0}.", channelUri);
            }
            System.Console.WriteLine("<enter> to leave...");
            System.Console.ReadLine();
        }
Exemple #2
0
    public static void Main(string[] args)
    {
        //<snippet2>
        // Create the server channel.
        TcpChannel serverChannel = new TcpChannel(9090);

        //</snippet2>

        // Register the server channel.
        ChannelServices.RegisterChannel(serverChannel);

        //<snippet3>
        // Show the name of the channel.
        Console.WriteLine("The name of the channel is {0}.",
                          serverChannel.ChannelName);
        //</snippet3>

        //<snippet4>
        // Show the priority of the channel.
        Console.WriteLine("The priority of the channel is {0}.",
                          serverChannel.ChannelPriority);
        //</snippet4>

        //<snippet5>
        // Show the URIs associated with the channel.
        ChannelDataStore data = (ChannelDataStore)serverChannel.ChannelData;

        foreach (string uri in data.ChannelUris)
        {
            Console.WriteLine("The channel URI is {0}.", uri);
        }
        //</snippet5>

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(RemoteObject), "RemoteObject.rem",
            WellKnownObjectMode.Singleton);

        //<snippet6>
        // Parse the channel's URI.
        string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
        if (urls.Length > 0)
        {
            string objectUrl = urls[0];
            string objectUri;
            string channelUri = serverChannel.Parse(objectUrl, out objectUri);
            Console.WriteLine("The object URL is {0}.", objectUrl);
            Console.WriteLine("The object URI is {0}.", objectUri);
            Console.WriteLine("The channel URI is {0}.", channelUri);
        }
        //</snippet6>

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
    }
        public static int PublishService()
        {
            RemotingService.RegisterRemotingChannel();
            TcpChannel ch = (TcpChannel)ChannelServices.GetChannel("tcp");
            Uri        u  = new Uri(ch.GetUrlsForUri("test")[0]);

            publicPort = u.Port;

            InstrumentationServiceBackend backend = new InstrumentationServiceBackend();

            System.Runtime.Remoting.RemotingServices.Marshal(backend, "InstrumentationService");

            return(publicPort);
        }
Exemple #4
0
    public static void Main(string[] args)
    {
        //<snippet1>
        // Specify the properties for the server channel.
        System.Collections.IDictionary dict =
            new System.Collections.Hashtable();
        dict["port"] = 9090;
        dict["authenticationMode"] = "IdentifyCallers";

        // Set up the server channel.
        TcpChannel serverChannel = new TcpChannel(dict, null, null);

        ChannelServices.RegisterChannel(serverChannel);
        //</snippet1>

        // Show the name and priority of the channel.
        Console.WriteLine("The name of the channel is {0}.",
                          serverChannel.ChannelName);
        Console.WriteLine("The priority of the channel is {0}.",
                          serverChannel.ChannelPriority);

        // Show the URIs associated with the channel.
        ChannelDataStore data = (ChannelDataStore)serverChannel.ChannelData;

        foreach (string uri in data.ChannelUris)
        {
            Console.WriteLine("The channel URI is {0}.", uri);
        }

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(RemoteObject), "RemoteObject.rem",
            WellKnownObjectMode.Singleton);

        // Parse the channel's URI.
        string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
        if (urls.Length > 0)
        {
            string objectUrl = urls[0];
            string objectUri;
            string channelUri = serverChannel.Parse(objectUrl, out objectUri);
            Console.WriteLine("The object URL is {0}.", objectUrl);
            Console.WriteLine("The object URI is {0}.", objectUri);
            Console.WriteLine("The channel URI is {0}.", channelUri);
        }

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
    }
Exemple #5
0
        [Test]         // TcpChannel (IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)
        public void Constructor3()
        {
            const string SERVICE_URI = "MarshalSvc";

            string []        urls;
            ChannelDataStore ds;
            TcpChannel       chn;

            MarshalObject marshal = new MarshalObject();

            var         port  = NetworkHelpers.FindFreePort();
            IDictionary props = new Hashtable();

            props ["name"]   = "marshal channel";
            props ["port"]   = port;
            props ["bindTo"] = IPAddress.Loopback.ToString();
            chn = new TcpChannel(props, null, null);

            ChannelServices.RegisterChannel(chn);

            Assert.AreEqual("marshal channel", chn.ChannelName, "#A1");
            urls = chn.GetUrlsForUri(SERVICE_URI);
            Assert.IsNotNull(urls, "#A2");
            Assert.AreEqual(1, urls.Length, "#A3");
            Assert.AreEqual($"tcp://{IPAddress.Loopback.ToString ()}:{port}/{SERVICE_URI}", urls [0], "#A6");
            ds = chn.ChannelData as ChannelDataStore;
            Assert.IsNotNull(ds, "#A4");
            Assert.AreEqual(1, ds.ChannelUris.Length, "#A5");
            Assert.AreEqual($"tcp://{IPAddress.Loopback.ToString ()}:{port}", ds.ChannelUris [0], "#A6");

            ChannelServices.UnregisterChannel(chn);

            chn = new TcpChannel((IDictionary)null, null, null);

            ChannelServices.RegisterChannel(chn);

            Assert.AreEqual("tcp", chn.ChannelName, "#B1");
            urls = chn.GetUrlsForUri(SERVICE_URI);
            Assert.IsNull(urls, "#B1");
            ds = chn.ChannelData as ChannelDataStore;
            Assert.IsNull(ds, "#B2");

            ChannelServices.UnregisterChannel(chn);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            remotePCS = new RemotePCSObject();

            TcpChannel channel = new TcpChannel(10000);

            ChannelServices.RegisterChannel(channel, false);
            RemotingServices.Marshal(remotePCS, remoteObjectName, typeof(RemotePCSObject));

            string[] urls = channel.GetUrlsForUri(remoteObjectName);

            Console.WriteLine("channel urls:");
            foreach (string url in urls)
            {
                Console.WriteLine("\t{0}", url);
            }

            Console.ReadLine();
        }
Exemple #7
0
        /// <summary>
        /// 根据指定的配置文档(ServerCfg.config)启动TCP服务,找不到该配置文件就找app.config
        /// </summary>
        /// <param name="msg"></param>
        public static RegisterServer <T> Init(T msg)
        {
            RegisterServer <T> reg = new RegisterServer <T>();

            try
            {
                if (File.Exists("ServerCfg.config"))
                {
                    RemotingConfiguration.Configure("ServerCfg.config", false);
                }
                else
                {
                    RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
                }
                WellKnownServiceTypeEntry swte = new WellKnownServiceTypeEntry(typeof(T), typeof(T).Name, WellKnownObjectMode.Singleton);
                RemotingConfiguration.ApplicationName = typeof(T).Name;
                RemotingConfiguration.RegisterWellKnownServiceType(swte);
                reg.Register(msg);
                IChannel   ch  = ChannelServices.GetChannel(RemotingConfiguration.ApplicationName);
                TcpChannel tch = ch as TcpChannel;
                if (tch != null)
                {
                    if (!reg.Channels.Contains(tch))
                    {
                        reg.Channels.Add(tch);
                    }
                    string[] ss = tch.GetUrlsForUri(swte.ObjectUri);
                    foreach (string uri in ss)
                    {
                        if (!reg.Uris.Exists(a => a.AbsoluteUri == uri))
                        {
                            reg.Uris.Add(new Uri(uri, UriKind.RelativeOrAbsolute));
                        }
                    }
                }
                return(reg);
            }
            catch (Exception e)
            {
                Logs.Create("启动消息服务失败:" + e.Message);
            }
            return(reg);
        }
Exemple #8
0
        internal TCPTeller(Type serviceType, int port, string serviceName)
        {
            Port = port;

            if (!IsAvailable())
            {
                throw new Exception("port address is full");
            }

            ServiceName = serviceName ?? serviceType.Name;

            var tc = new TcpChannel(Port);

            ChannelServices.RegisterChannel(tc, true);

            RemotingConfiguration.RegisterWellKnownServiceType(serviceType, ServiceName, WellKnownObjectMode.SingleCall);

            TCPUri = tc.GetUrlsForUri(ServiceName).FirstOrDefault();
        }
Exemple #9
0
    public static void Main()
    {
        // Create a remotable object.
        TcpChannel tcpChannel = new TcpChannel(8085);

        WellKnownServiceTypeEntry WKSTE =
            new WellKnownServiceTypeEntry(typeof(HelloService),
                                          "Service",
                                          WellKnownObjectMode.Singleton);

        RemotingConfiguration.RegisterWellKnownServiceType(WKSTE);

        RemotingConfiguration.ApplicationName = "HelloServer";

        // Print out the urls for the HelloServer.
        string[] urls = tcpChannel.GetUrlsForUri("HelloServer");

        foreach (string url in urls)
        {
            System.Console.WriteLine("{0}", url);
        }
    }
Exemple #10
0
        static int Main(string[] argv)
        {
            XmlConfigurator.Configure();
            //AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            // Get ArchAngel PID from command line arguments
            if (argv.Length != 2)
            {
                Console.WriteLine("This application cannot be run separately from ArchAngel");
                return(-1);
            }

            ArchAngelPID = Int32.Parse(argv[0]);
            string uri = argv[1];

            // Create an instance of a channel
            TcpChannel channel = new TcpChannel(0);

            ChannelServices.RegisterChannel(channel, false);

            // Register as an available service with the name CommandReceiver
            // Register as a Singleton so only one runs at a time.
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(CommandReceiver),
                "CommandReceiver",
                WellKnownObjectMode.Singleton);

            ThreadStart start  = SearchForArchAngelProcess;
            Thread      thread = new Thread(start);

            thread.Start();

            DebugProcessInfoService dpis = (DebugProcessInfoService)Activator.GetObject(
                typeof(DebugProcessInfoService), uri);

            if (dpis == null)
            {
                // ArchAngel is either not running or not responding. The process should die either way.
                EndDebugProcess.Set();
            }
            else
            {
                // Get the URI of our remoting services, so we can tell the ArchAngel
                // process how to contact us.
                string   objectUri = "";
                string[] urls      = channel.GetUrlsForUri("CommandReceiver");
                if (urls.Length > 0)
                {
                    string objectUrl  = urls[0];
                    string channelUri = channel.Parse(objectUrl, out objectUri);
                    objectUri = channelUri + objectUri;
                }
                if (string.IsNullOrEmpty(objectUri))
                {
                    throw new Exception(
                              "The Debug Process could not register itself with .Net" +
                              "remoting. This is a serious error and must be reported to Slyce.");
                }

                // Inform ArchAngel that we have started.
                dpis.Started(objectUri);
            }

            // Wait for the signal to end the app.
            EndDebugProcess.WaitOne();
            return(0);
        }