Beispiel #1
0
 private void StopChannel()
 {
     if (_channel == null)
     {
         throw new Exception("There is no active channel?!");
     }
     _channel.StopListening(null);
     _channel = null;
 }
Beispiel #2
0
    static void Main( )
    {
        try
        {
            string myString;
// <Snippet2>
            int myPort = 8085;
            // Creating the 'IDictionary' to set the server object properties.
            IDictionary myDictionary = new Hashtable();
            myDictionary["name"]     = "MyServerChannel1";
            myDictionary["priority"] = 2;
            myDictionary["port"]     = 8085;
            // Set the properties along with the constructor.
            HttpServerChannel myHttpServerChannel = new HttpServerChannel(myDictionary,
                                                                          new BinaryServerFormatterSinkProvider());
            // Register the server channel.
            ChannelServices.RegisterChannel(myHttpServerChannel);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyHelloServer),
                                                               "SayHello", WellKnownObjectMode.SingleCall);
            myHttpServerChannel.WantsToListen = true;
            // Start listening on a specific port.
            myHttpServerChannel.StartListening((object)myPort);
            // Get the name of the channel.
            Console.WriteLine("ChannelName : " + myHttpServerChannel.ChannelName);
            // Get the channel priority.
            Console.WriteLine("ChannelPriority : " + myHttpServerChannel.ChannelPriority);
            // Get the schema of the channel.
            Console.WriteLine("ChannelScheme : " + myHttpServerChannel.ChannelScheme);
            // Get the channel URI.
            Console.WriteLine("GetChannelUri : " + myHttpServerChannel.GetChannelUri());
            // Indicates whether 'IChannelReceiverHook' wants to be hooked into the outside listener service.
            Console.WriteLine("WantsToListen : " + myHttpServerChannel.WantsToListen);
// </Snippet2>
// <Snippet3>
            // Extract the channel URI and the remote well known object URI from the specified URL.
            Console.WriteLine("Parsed : " +
                              myHttpServerChannel.Parse(myHttpServerChannel.GetChannelUri() +
                                                        "/SayHello", out myString));
            Console.WriteLine("Remote WellKnownObject : " + myString);
            Console.WriteLine("Hit <enter> to stop listening...");
            Console.ReadLine();
            // Stop listening to channel.
            myHttpServerChannel.StopListening((object)myPort);
// </Snippet3>
            Console.WriteLine("Hit <enter> to exit...");
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine("The following exception is raised on server side : " + ex.Message);
        }
    }
Beispiel #3
0
	static void Main ()
	{
		SoapServerFormatterSinkProvider sfsp = new SoapServerFormatterSinkProvider ();
		sfsp.TypeFilterLevel = TypeFilterLevel.Full;
		HttpServerChannel channel = new HttpServerChannel ("Serv", 8080, sfsp);
#if NET_2_0
		ChannelServices.RegisterChannel (channel, false);
#else
		ChannelServices.RegisterChannel (channel);
#endif

		ServerImpl impl = new ServerImpl ();
		RemotingServices.Marshal (impl, "Server.rem");
		channel.StartListening (null);
		Console.ReadLine ();
		channel.StopListening (null);
	}
Beispiel #4
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         button2.Enabled = false;
         Application.DoEvents();
         //stop the channel
         _chnl.StopListening(null);
         ChannelServices.UnregisterChannel(_chnl);
         _chnl           = null;
         button1.Enabled = true;
     }
     catch (Exception ex)
     {
         CommonLib.HandleException(ex);
         button1.Enabled = false;
         button2.Enabled = true;
     }
 }
Beispiel #5
0
        /// <summary>
        /// 停止此服务。
        /// </summary>
        protected void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            try
            {
                if (ChannelServices.RegisteredChannels.Length > 0)
                {
                    IChannel[] channels = ChannelServices.RegisteredChannels;

                    //					现在改成TCP、HTTP的都能停
                    for (int i = 0; i < channels.Length; i++)
                    {
                        string sChannelName = channels[i].ChannelName;
                        if (sChannelName == "tcp")
                        {
                            TcpServerChannel channel = (TcpServerChannel)channels[i];
                            channel.StopListening(null);
                            ChannelServices.UnregisterChannel(channel);
                        }
                        else
                        {
                            HttpServerChannel channel = (HttpServerChannel)channels[i];
                            channel.StopListening(null);
                            ChannelServices.UnregisterChannel(channel);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                System.Windows.Forms.MessageBox.Show("连接数据库出错" + exception.ToString(), "操作提示");
            }
            finally
            {
            }
        }