Пример #1
0
	static int Main ()
	{
		SoapServerFormatterSinkProvider serverFormatter = new SoapServerFormatterSinkProvider ();
		serverFormatter.TypeFilterLevel = TypeFilterLevel.Full;

		Hashtable ht = new Hashtable ();
		ht ["name"] = "hydraplus";
		ht ["port"] = 8081;
		ht ["authorizedGroup"] = "everyone";

		HttpChannel channel = new HttpChannel (ht, null, serverFormatter);
#if NET_2_0
		ChannelServices.RegisterChannel (channel, false);
#else
		ChannelServices.RegisterChannel (channel);
#endif

		WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry (
			typeof (ServerTalk), "hydraplus.soap",
			WellKnownObjectMode.Singleton);
		RemotingConfiguration.RegisterWellKnownServiceType (entry);

		ServerTalk.NewUser = new delUserInfo (NewClient);
		ServerTalk.DelUser = new delRemoveUser (RemoveClient);
		ServerTalk.ClientToHost = new delCommsInfo (ClientToHost);

		clientConnected = new AutoResetEvent (false);
		clientDisconnected = new AutoResetEvent (false);

		// wait for client to connect
		if (!clientConnected.WaitOne (20000, false)) {
			ReportFailure ("No client connected in time.");
			return 1;
		}

		// wait for message to arrive
		while (true) {
			Thread.Sleep (50);
			if (ServerTalk.ClientToServerQueue.Count > 0) {
				CommsInfo info = (CommsInfo) ServerTalk.ClientToServerQueue.Dequeue ();
				ClientToHost (info);
				break;
			}
		}

		// send message to client
		ServerTalk.RaiseHostToClient (client.Id, "txt", receivedMsg);

		// wait for client to disconnect
		if (clientConnected.WaitOne (2000, false)) {
			ReportFailure ("Client did not disconnect in time.");
			return 2;
		}

		return 0;
	}
Пример #2
0
    public static void Main()
    {
        // Create a remotable object.
        HttpChannel httpChannel = new HttpChannel(8085);

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

        RemotingConfiguration.RegisterWellKnownServiceType(WKSTE);

        RemotingConfiguration.ApplicationName = "HelloServer";

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

        foreach (string url in urls)
        {
            System.Console.WriteLine("{0}", url);
        }
    }
Пример #3
0
        // Registers a new Remoting httpChannel utilizing SOAP formatter for serialization
        private void RegisterChannel()
        {
            Console.WriteLine("[Remoting Server]: Registering httpChannel");

            try
            {
                // Set the TypeFilterLevel to Full since callbacks require additional security requirements
                SoapServerFormatterSinkProvider serverFormatter = new SoapServerFormatterSinkProvider();
                serverFormatter.TypeFilterLevel = TypeFilterLevel.Full;

                // We have to change the name since we can't have two channels with the same name.
                Hashtable ht = new Hashtable();
                ht["name"] = "ServerChannel";
                ht["port"] = 9000;

                // Now create and register our custom HttpChannel
                HttpChannel channel = new HttpChannel(ht, null, serverFormatter);
                ChannelServices.RegisterChannel(channel, false);

                // Register a 'Well Known Object' type in Singleton mode
                string identifier        = "RUETalk";
                WellKnownObjectMode mode = WellKnownObjectMode.Singleton;

                // Register our Object model (RemotingComms)
                WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry(typeof(RemotingComms), identifier, mode);
                RemotingConfiguration.RegisterWellKnownServiceType(entry);
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("Prefix already in use."))
                {
                    Console.WriteLine("[Remoting Server ERROR]: Message - " + e.Message);
                }
                else
                {
                    Console.WriteLine("[Remoting Server]: httpChannel Registered");
                }
            }
        }
Пример #4
0
    public static void Main()
    {
        ChannelServices.RegisterChannel(new HttpChannel(8090));

        WellKnownServiceTypeEntry wkste =
            new WellKnownServiceTypeEntry(typeof(RemoteObject),
                                          "RemoteObject",
                                          WellKnownObjectMode.Singleton);

        RemotingConfiguration.RegisterWellKnownServiceType(wkste);

        RemoteObject RObj =
            (RemoteObject)Activator.GetObject(typeof(RemoteObject),
                                              "http://localhost:8090/RemoteObject");

        LocalObject LObj = new LocalObject();

        RObj.Method1(LObj);

        Console.WriteLine("Press Return to exit...");
        Console.ReadLine();
    }
Пример #5
0
        static void Main(string[] args)
        {
            // create a TCP channel and bind it to port 8888
            TcpChannel remotingChannel = new TcpChannel(8888);

            // register the channel, the second parameter is ensureSecurity
            // I have set it to false to disable encryption and signing
            // for more information see section Remarks in https://msdn.microsoft.com/en-us/library/ms223155(v=vs.90).aspx
            ChannelServices.RegisterChannel(remotingChannel, false);

            // create a new servicetype of type RemoteMath named "rMath" and of type SingleCall
            // SingleCall: a new object will be created for each call
            // as opposed to WellKnownObjectMode.Singleton where there is one object for all calls (and clients)
            WellKnownServiceTypeEntry remoteObject = new WellKnownServiceTypeEntry(typeof(RemoteMath), "rMath", WellKnownObjectMode.SingleCall);

            // register the remoteObject servicetype
            RemotingConfiguration.RegisterWellKnownServiceType(remoteObject);

            Console.WriteLine("Registered service");
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
Пример #6
0
        private void registerChannel()
        {
            // set typefilterlevel to higher security
            SoapServerFormatterSinkProvider serverFormatter = new SoapServerFormatterSinkProvider();

            serverFormatter.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            // setup dictionary with values
            Hashtable ht = new Hashtable();

            ht["name"] = "ServerChannel";
            ht["port"] = 9000;
            // create and register the channel
            HttpChannel channel = new HttpChannel(ht, null, serverFormatter);

            ChannelServices.RegisterChannel(channel, false);
            // register a wellknown type in singleton mode
            string identifier = "commBuffer";
            WellKnownObjectMode       mode  = WellKnownObjectMode.Singleton;
            WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry(typeof(osgCommBuffer),
                                                                            identifier, mode);

            RemotingConfiguration.RegisterWellKnownServiceType(entry);
        }
Пример #7
0
        /// <summary>
        /// 根据默认的配置文档(app.config)启动TCP服务
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="port"></param>
        public static RegisterServer <T> Intialize(T msg, string serviceName, int port = 8888)
        {
            RegisterServer <T> reg = new RegisterServer <T>();

            try
            {
                BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                //BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                //IDictionary props = new Hashtable();
                //props["port"] = port;
                TcpServerChannel servChannel = new TcpServerChannel(serviceName, port, serverProv);
                ChannelServices.RegisterChannel(servChannel, false);
                if (!reg.Channels.Contains(servChannel))
                {
                    reg.Channels.Add(servChannel);
                }
                WellKnownServiceTypeEntry swte = new WellKnownServiceTypeEntry(typeof(T), serviceName, WellKnownObjectMode.Singleton);
                //RemotingConfiguration.ApplicationName = serviceName;
                RemotingConfiguration.RegisterWellKnownServiceType(swte);
                reg.Register(msg, serviceName);
                string[] ss = servChannel.GetUrlsForUri(serviceName);
                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);
        }
        static void Main(string[] args)
        {
            ConfigurationManager           cm  = (ConfigurationManager)ConfigurationSettings.GetConfig("Framework");
            EventNotificationConfiguration enc = cm.EventNotificationConfig;
            //set up the network channel for accepting calls from event clients and making calls
            //to the event clients.
            IDictionary props = new Hashtable();

            props["port"] = Int32.Parse(enc.GetPortNumber());

            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();

            provider.TypeFilterLevel = TypeFilterLevel.Full;
            HttpChannel channel = new HttpChannel(props, null, provider);

            ChannelServices.RegisterChannel(channel);
            //register the remote object type.
            WellKnownServiceTypeEntry wste = new WellKnownServiceTypeEntry(typeof(EventServer), enc.GetObjectUri(), WellKnownObjectMode.Singleton);

            RemotingConfiguration.ApplicationName = enc.GetApplicationName();
            RemotingConfiguration.RegisterWellKnownServiceType(wste);
            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }
 public static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
 }
Пример #10
0
 public static void RegisterWellKnownServiceType(WellKnownServiceTypeEntry entry)
 {
 }
Пример #11
0
 /// <summary>
 /// Starts the server with specified product name and version.
 /// </summary>
 /// <param name="cProductName">Name of the c product.</param>
 /// <param name="cProductVersion">The c product version.</param>
 public static void Start(string cProductName, string cProductVersion)
 {
     if (!started)
     {
         ProductName    = cProductName;
         ProductVersion = cProductVersion;
         //inicjalizacja kanalu
         started = true;
         try
         {
             TcpServerChannel channel;
             //        SoapServerFormatterSinkProvider ftProvider = new SoapServerFormatterSinkProvider();
             //        ftProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
             //        ftProvider.Next=new  System.Runtime.Remoting.MetadataServices.SdlChannelSinkProvider();
             BinaryServerFormatterSinkProvider ftProvider = new BinaryServerFormatterSinkProvider();
             ftProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
             channel = new TcpServerChannel(null, AppConfigManagement.ConsoleRemotingHTTPport, ftProvider);
             //rejestracja kana³u
             ChannelServices.RegisterChannel(channel, false);
         }
         catch (Exception ex)
         {
             EventLogMonitor.WriteToEventLog
             (
                 String.Format(Resources.ConsoleInterface_ChannelRegistrationError, ex.Message),
                 EventLogEntryType.Error, (int)Error.CommServer_CommServerComponent, 267
             );
         }
         //rejestracja OPCRealtimeDataAccess
         WellKnownServiceTypeEntry remObj = new WellKnownServiceTypeEntry
                                            (
             typeof(BaseStation.ConsoleIterface),
             "CommServerConsole",
             WellKnownObjectMode.Singleton
                                            );
         RemotingConfiguration.RegisterWellKnownServiceType(remObj);
         //inicjalizacja listy protokolow :
         //inicjalizacja listy stacji :
         stationlist = new SortedList <long, Statistics.StationStatistics.StationStatisticsInternal>(Statistics.stationList.Count);
         foreach (Statistics.StationStatistics obj in Statistics.stationList)
         {
             stationlist.Add(((Statistics.StationStatistics)obj).myStat.myID, ((Statistics.StationStatistics)obj).myStat);
         }
         //inicjalizacja listy segmentow :
         segmentlistpairs = new SortedList <long, StatisticAndIUpdatePair <Statistics.SegmentStatistics.SegmentStatisticsInternal> >(Statistics.segmentList.Count);
         segmentlist      = new SortedList <long, Statistics.SegmentStatistics.SegmentStatisticsInternal>(Statistics.segmentList.Count);
         foreach (Statistics.SegmentStatistics obj in Statistics.segmentList)
         {
             segmentlist.Add(obj.myStat.MyID, obj.myStat);
             segmentlistpairs.Add(
                 obj.myStat.MyID, new StatisticAndIUpdatePair <Statistics.SegmentStatistics.SegmentStatisticsInternal>
                     (obj.myStat, obj));
         }
         //inicjalizacja listy interfejsow :
         interfacelistpairs = new SortedList <ulong, StatisticAndIUpdatePair <Statistics.InterfaceStatistics.InterfaceStatisticsInternal> >(Statistics.interfaceList.Count);
         interfacelist      = new SortedList <ulong, Statistics.InterfaceStatistics.InterfaceStatisticsInternal>(Statistics.interfaceList.Count);
         foreach (Statistics.InterfaceStatistics obj in Statistics.interfaceList)
         {
             interfacelist.Add(obj.myStat.myID_Internal, obj.myStat);
             interfacelistpairs.Add(
                 obj.myStat.myID_Internal, new StatisticAndIUpdatePair <Statistics.InterfaceStatistics.InterfaceStatisticsInternal>
                     (obj.myStat, obj));
         }
         listSegmentStates   = new SortedList <long, Statistics.SegmentStatistics.States>(segmentlistpairs.Count);
         listStationStates   = new SortedList <long, int>(stationlist.Count);
         listInterfaceStates = new SortedList <ulong, Statistics.InterfaceStatistics.InterfaceState>(interfacelistpairs.Count);
     }
 }
Пример #12
0
        public Core(string configurationFile)
        {
            // Fix working directory
            string path = Assembly.GetExecutingAssembly().Location;

            if (path.LastIndexOf(Path.DirectorySeparatorChar) > 0)
            {
                path = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar));
                Environment.CurrentDirectory = path;
            }
            Core.Output("Core", "Path set to: " + Environment.CurrentDirectory);

            // Read configuration file
            this._configurationFile = configurationFile;
            if (!this.ReadConfiguration())
            {
                Environment.Exit(ExitCodes.NO_CONFIGURATION);
                return;
            }

            // Prepare remoting callbacks
            ServerCommunication.OnAuthorizeClient = new AuthorizeClientDelegate(this.AuthorizeClient);
            Core.Output("Core", "Registered remoting callbacks");

            // Start remoting server
            try
            {
                BinaryServerFormatterSinkProvider serverFormatter = new BinaryServerFormatterSinkProvider();
                serverFormatter.TypeFilterLevel = TypeFilterLevel.Full;
                this._channelName += new Random().Next(int.MaxValue);
                this._channel      = new IpcChannel(this._channelName);
                ChannelServices.RegisterChannel(this._channel, false);
                Core.Output("Core", "Registered remoting channel");
            }
            catch
            {
                Core.Output("Core", "Unable to registered remoting channel");
                Environment.Exit(ExitCodes.REMOTING_FAILED);
            }

            // Register remoting API
            try
            {
                WellKnownObjectMode       mode  = WellKnownObjectMode.Singleton;
                WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry(typeof(ServerCommunication), "ServerCommunication", mode);
                RemotingConfiguration.RegisterWellKnownServiceType(entry);
                Core.Output("Core", "Registered remoting API");
            }
            catch
            {
                Core.Output("Core", "Unable to registered remoting API");
                Environment.Exit(ExitCodes.REMOTING_FAILED);
            }

            // Initial start of bots
            List <string> bots;

            lock (this._bots)
            {
                bots = new List <string>(this._bots.Keys);
                foreach (string bot in bots)
                {
                    if (this._bots[bot].Enabled)
                    {
                        this.StartShell(bot);
                    }
                    Thread.Sleep(1000);
                }
            }

            // Clean shutdown

            /*lock (this._bots) bots = new List<string>(this._bots.Keys);
             * foreach (string bot in bots)
             * {
             *  lock (this._bots)
             *  {
             *      if (!this._bots[bot].Enabled) continue;
             *
             *  }
             * }*/
        }