Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            ServiceHost serviceHost = null;

            try
            {
                serviceHost = new ServiceHost(typeof(PortTesterService));
                serviceHost.Open();

                ShowInfo(serviceHost);
                Console.Out.WriteLine("Press X to stop server");
                while (true)
                {
                    if (Console.ReadKey(true).Key == ConsoleKey.X)
                    {
                        break;
                    }
                }

                CloseHost(serviceHost);
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine(exception);
                Console.Error.WriteLine("Aborting host");
                serviceHost?.Abort();
            }
        }
        public void ServerAncClientExceptionsEndpointBehavior()
        {
            var hook = new ExceptionsEndpointBehaviour();
            var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var serv = new ExceptionService();
            using (var host = new ServiceHost(serv, new Uri[] { new Uri(address), }))
            {
                var b = new NetNamedPipeBinding();
                var serverEndpoint = host.AddServiceEndpoint(typeof(IExceptionService), b, address);
                serverEndpoint.Behaviors.Add(hook);

                host.Open();

                var f = new ChannelFactory<IExceptionService>(b);
                f.Endpoint.Behaviors.Add(hook);

                var c = f.CreateChannel(new EndpointAddress(address));

                try
                {
                    c.DoException("message");
                }
                catch (InvalidOperationException ex)
                {
                    StringAssert.AreEqualIgnoringCase("message", ex.Message);
                }
                host.Abort();
            }
        }
Exemplo n.º 3
0
        public void Start()
        {
            // Can only be started once.
            if (_active)
            {
                return;
            }

            _active = true;


            // Step 2 Create a ServiceHost instance
            _host = new ServiceHost(typeof(TicTacToeService));

            try
            {
                // step 5 Start the service
                _host.Open();
                _callback("Service Started");
            }
            catch (Exception ce)
            {
                ReportException(ce);
                _host?.Abort();
                _active = false;
            }
        }
Exemplo n.º 4
0
 public void Stop()
 {
     _host?.Abort();
     _host?.Close();
     _host     = null;
     IsStarted = false;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Clean up the resources used by the Athena WCF log server service.
 /// </summary>
 protected override void OnStop()
 {
     try
     {
         m_WcfHost?.Close();
     }
     catch
     {
         m_WcfHost?.Abort();
     }
 }
Exemplo n.º 6
0
 private void StartStopHost(object singletonInstance, params Uri[] baseAddresses)
 {
     if (ReceiveingInProgress)
     {
         btnStartServer.Text  = @"Start Receiving Messages";
         ReceiveingInProgress = false;
         try
         {
             _mSvcHost.Close();
             label1.Visible = false;
         }
         catch (Exception ex)
         {
             _mSvcHost?.Abort();
             MessageBox.Show(@"Error: " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         try
         {
             _mSvcHost = new ServiceHost(singletonInstance, baseAddresses);
             _mSvcHost.Open();
             ReceiveingInProgress = true;
             btnStartServer.Text  = "Stop";
             label1.Text          = "Server is running and listening to incoming messages";
             label1.BackColor     = Color.GreenYellow;
             label1.Visible       = true;
         }
         catch (Exception ex)
         {
             _mSvcHost?.Abort();
             MessageBox.Show(@"Error: " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Exemplo n.º 7
0
 private void StartStopHost(object singletonInstance, params Uri[] baseAddresses)
 {
     if (ReceiveingInProgress)
     {
         btnStartServer.Text  = @"Start Receiving Messages";
         ReceiveingInProgress = false;
         try
         {
             _mSvcHost.Close();
             label1.Visible = false;
         }
         catch (Exception)
         {
             _mSvcHost?.Abort();
         }
     }
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            string service_url = "http://localhost:2020/manufacturerservice/a";
            ServiceHost host = new ServiceHost(typeof(manufacturerAServiceImplementation));
            host.AddServiceEndpoint(typeof(ImanufacturerAService), new BasicHttpBinding(), service_url);

            try
            {
                host.Open();
                Console.WriteLine();
                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                host.Abort();
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            ServiceHost hostObj = null;

            try
            {
                hostObj.Abort();
                label2.Text     = "Server OFF";
                label3.Text     = "Klik ON untuk menghidupkan server";
                button2.Enabled = false;
                button1.Enabled = true;
            }
            catch (Exception ex)
            {
                button1.Enabled = false;
                button2.Enabled = true;
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(Passagens.Services.ClienteService));
            var         uri  = new Uri("http://localhost:8080/clientes");

            try
            {
                host.AddServiceEndpoint(typeof(Passagens.Interfaces.IClienteService), new BasicHttpBinding(), uri);
                host.Open();
                ExibeInformacoesServico(host);
                Console.ReadKey();
                host.Close();
            }
            catch (Exception ex)
            {
                host.Abort();
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            var host = new ServiceHost(typeof(RoutingService));

            try
            {
                host.Open();
                PrintServiceInfo(host);
                Console.ReadLine();
                host.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                host.Abort();
            }

            Console.WriteLine("press [enter] to exit.");
            Console.ReadLine();
        }
Exemplo n.º 12
0
        private void cmdExit_Click(object sender, EventArgs e)
        {
            if (PolarOrbit != null)
            {
                PolarOrbit.Abort();
                PolarOrbit.Close();
                PolarOrbit = null;
            }

            if (_BGWorker != null)
            {
                //_BGWorker.CancelAsync();
                _BGWorker.Dispose();
                _BGWorker = null;
            }


            //HQServer.StopServer();
            Application.Exit();
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            ServiceHost selfHost = new ServiceHost(typeof(CollectLifeService));

            try
            {
                selfHost.Open();
                Console.WriteLine("汇生活数据服务(绑定:basicHttpBinding,端口:18881)已启动就绪!");
                Console.WriteLine("终止服务请按任意键!");
                Console.WriteLine();
                Console.ReadLine();

                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("汇生活数据服务发生异常: {0}", ce.Message);
                selfHost.Abort();
            }
        }
Exemplo n.º 14
0
Arquivo: Program.cs Projeto: pgori/wcf
        static void Main(string[] args)
        {
            ServiceHost host     = new ServiceHost(typeof(ClienteService));
            Uri         endereco = new Uri("http://localhost:8080/clientes");

            host.AddServiceEndpoint(typeof(IClienteService), new BasicHttpBinding(), endereco);
            try
            {
                host.Open();
                ExibeInformacoesServico(host);
                Console.ReadLine();
                host.Close();
            }
            catch (Exception e)
            {
                host.Abort();
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            Uri              baseAddress = new Uri("http://localhost:60002/");
            ServiceHost      mojHost     = new ServiceHost(typeof(Service1), baseAddress);
            BasicHttpBinding b           = new BasicHttpBinding();

            Uri               baseAddress2 = new Uri("http://localhost:50002/");
            ServiceHost       mojHost2     = new ServiceHost(typeof(FindFile), baseAddress2);
            WSDualHttpBinding b2           = new WSDualHttpBinding();

            b.TransferMode            = TransferMode.Streamed;
            b.MaxReceivedMessageSize  = 99999999;
            b.MaxBufferSize           = 8192;
            b2.MaxReceivedMessageSize = 99999999;

            try
            {
                mojHost2.AddServiceEndpoint(typeof(IFindFile), b2, "ICallbackFile");
                ServiceEndpoint         endpoint1 = mojHost.AddServiceEndpoint(typeof(IService1), b, baseAddress);
                ServiceMetadataBehavior smb       = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                mojHost.Description.Behaviors.Add(smb);
                var serviceMetadataBehavior = new ServiceMetadataBehavior {
                    HttpGetEnabled = true
                };
                mojHost2.Description.Behaviors.Add(serviceMetadataBehavior);
                mojHost.Open();
                mojHost2.Open();
                Console.WriteLine("Server started. Stream is up.");
                Console.WriteLine("Press <ENTER> to finish!\n");
                Console.ReadLine();
                mojHost.Close();
                mojHost2.Close();
                Console.WriteLine("Finished");
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("Exception: {0}", ce.Message);
                mojHost.Abort();
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Infinite running service listener for the GetIdentity web service
        /// </summary>
        /// <param name="uninteresting"></param>
        /// <param name="portNumber">The port number to listen on</param>
        static void ServiceListener(object portNumber)
        {
            if (portNumber == null ||
                (portNumber is int && (int)portNumber <= 0))
            {
                portNumber = 8001;
            }

            Uri         baseAddress = new Uri("http://localhost:" + portNumber.ToString() + "/iTunesServiceInfo");
            ServiceHost serviceHost = new ServiceHost(typeof(iTunesServiceInfo), baseAddress);

            serviceHost.AddServiceEndpoint(typeof(IiTunesInfoService), new WSHttpBinding(), "iTunesServiceInfo");

            // Enable Mex

            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();

            smb.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(smb);

            try
            {
                // Run indefinitely:

                serviceHost.Open();
                LogAnEvent(serviceHost, "Started listening on port " + portNumber.ToString());
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    LogAnEvent(serviceHost, "Exception received by the web service: " + ex.ToString(), LogSeverity.Error);
                }
            }
            finally
            {
                LogAnEvent(serviceHost, "Stopped web listener");
                serviceHost.Abort();
            }
        }
        /// <summary>
        /// Activates the WCF services.
        /// </summary>
        /// <exception cref="System.Exception">Could not activate WCF SolarEdgeService</exception>
        public void ActivateServices()
        {
            lock (ServiceLocker)
            {
                if (IsActivated)
                {
                    DeactivateServices();
                }

                SolarEdgeServiceHost = new ServiceHost(typeof(SolarEdgeWCFService))
                {
                    //OpenTimeout = TimeSpan.FromSeconds(5),
                    //CloseTimeout = TimeSpan.FromSeconds(2),
                };

                try
                {
                    SolarEdgeServiceHost.Open();
                }
                catch (Exception E)
                {
                    SolarEdgeServiceHost.Abort();
                    SolarEdgeServiceHost = null;
                    log.Error("Could not activate WCF SolarEdgeService", E);
                    throw new Exception("Could not activate WCF SolarEdgeService", E);
                }



                DataFetcher.Instance.SolarEdgeDataUpdated        += Instance_SolarEdgeDataUpdated;
                DataFetcher.Instance.SolarEdgeDataIsValidChanged += Instance_SolarEdgeDataIsValidChanged;

                if (SolarEdgeServiceSettings.Default.HeartbeatTimerIntervalMs > 0)
                {
                    StartHeartbeatTimer();
                }

                IsActivated = true;
            }
            log.Debug("Servicehost for SolarEdgeService opend.");
        }
Exemplo n.º 18
0
        private void StartServer()
        {
            _host = new ServiceHost(typeof(IndexService));
            _host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "localhost");
            try
            {
                _host.Open();
                richTextBoxLog.AppendText("Server is running on : " + Environment.NewLine);
                foreach (var baseAddress in _host.BaseAddresses)
                {
                    richTextBoxLog.AppendText(baseAddress.AbsoluteUri + Environment.NewLine);
                }
                SetToolStripStatus("Online", Color.Chartreuse);

                _indexService = new IndexService();
                StatusEventListner(_indexService);
                _indexService.CreateIndex();

                if (_indexService.GetIndexStatus())
                {
                    toolStripStatusLabelIndexStatusValue.Text = "Index ready";
                }
                toolStripStatusLabelIndexStatusValue.Text = "Indexing files";
            }
            catch (CommunicationObjectFaultedException ex)
            {
                MessageBox.Show("could not start server" + Environment.NewLine + ex);
            }
            catch (Exception ex)
            {
                richTextBoxLog.AppendText(ex.Message + Environment.NewLine);
                MessageBox.Show("Error" + ex.Message);
            }
            finally
            {
                if (_host.State == CommunicationState.Faulted)
                {
                    _host.Abort();
                }
            }
        }
        public PlayerCommunicationServer(Guid serverGUID)
        {
            //serverGUID = new Guid("7639dc4b-35c1-4376-abbc-ccfa42e30825");
            //var baseAddress = new Uri("net.pipe://localhost/LogRecorderAndPlayer");

            ServiceInstance = new PlayerCommunicationService();

            //ServiceHost = new ServiceHost(ServiceInstance, baseAddress);
            try
            {
                var binding = new NetNamedPipeBinding();
                binding.Security.Mode = NetNamedPipeSecurityMode.None;
                binding.Security.Transport.ProtectionLevel = ProtectionLevel.None;


                ServiceHost = new ServiceHost(ServiceInstance, new Uri($"net.pipe://localhost/{serverGUID.ToString().Replace("-", "")}"));
                var endpoint = ServiceHost.AddServiceEndpoint(typeof(PlayerCommunicationServiceInterface), binding, $"LRAPService{serverGUID.ToString().Replace("-", "")}");
                ServiceHost.Open();


                //var binding = new NetNamedPipeBinding();
                ////binding.Security.Mode = SecurityMode.None;
                ////binding.Security.Message.NegotiateServiceCredential = false;
                ////binding.Security.Message.ClientCredentialType = MessageCredentialType.None;

                //ServiceHost.AddServiceEndpoint(typeof(PlayerCommunicationServiceInterface), binding, $"{serverGUID.ToString().Replace("-", "")}");

                ////var smb = new ServiceMetadataBehavior();
                ////smb.HttpGetEnabled = true;
                ////ServiceHost.Description.Behaviors.Add(smb);

                //ServiceHost.Open();
            }
            catch (Exception ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                ServiceHost.Abort();
                ServiceHost = null;
                throw;
            }
        }
Exemplo n.º 20
0
        public void StartTCPServer()
        {
            // Step 1 Create a URI to serve as the base address.
            Uri baseAddress = new Uri("http://localhost:9119/TCPServer/");

            // Step 2 Create a ServiceHost instance
            ServiceHost selfHost = new ServiceHost(typeof(TCPService.TCPService), baseAddress);

            try
            {
                // Step 3 Add a service endpoint.
                selfHost.AddServiceEndpoint(typeof(TCPService.ITCPService), new WSHttpBinding(), "TCPServer");

                // Step 4 Enable metadata exchange.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                // Step 5 Start the service.
                selfHost.Open();
                if (LogEvent != null)
                {
                    LogEvent("TCPServer Host has started");
                }

                // Close the ServiceHostBase to shutdown the service.
                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                if (LogEvent != null)
                {
                    LogEvent("An exception occurred: " + ce.Message);
                }
                selfHost.Abort();
                if (LogEvent != null)
                {
                    LogEvent("TCPServer Host has Aborted");
                }
            }
        }
Exemplo n.º 21
0
        static async Task Main(string[] args)
        {
            GetSettingsForReceiver();

            ConsolePrintManager.Instance.PrintHelp();

            await StockProcessing.Instance.Initialize();

            var host            = new ServiceHost(typeof(StockService));
            var serviceEndpoint = host.Description.Endpoints.First();

            serviceEndpoint.Address = new EndpointAddress($"soap.udp://{ReceiverAddress}:34197/StockService");

            StockProcessing.Instance.SetDelayTime(DelayInSeconds);

            try
            {
                host.Open();

                ConsoleKey key;
                do
                {
                    key = Console.ReadKey().Key;

                    if (key == ConsoleKey.Enter)
                    {
                        ConsolePrintManager.Instance.PrintMessage("Statistics requested. Calculating...");
                        ConsolePrintManager.Instance.PrintStatistics(await StockProcessing.Instance.GetStatistics());
                        ConsolePrintManager.Instance.ClearMessage();
                    }
                } while (key != ConsoleKey.Escape);

                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.ReadKey();
                host.Abort();
            }
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            // Step 1: Create a URI to serve as the base address.
            // 创建基址的 URI
            // http://localhost:8000/WcfServiceTest/ 与 WcfServiceLibrary项目的App.config的baseAddress填写的URI的前一部分一致
            Uri baseAddress = new Uri("http://localhost:8000/WcfServiceTest/");

            // Step 2: Create a ServiceHost instance.
            // 创建用于承载服务的类实例
            ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);

            try
            {
                // Step 3: Add a service endpoint.
                // 创建服务终结点, CalculatorService是WcfServiceLibrary项目的方法实现的类
                // 呼应WcfServiceLibrary项目的App.config的baseAddress
                selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");

                // Step 4: Enable metadata exchange.
                // 启用元数据交换
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                // Step 5: Start the service.
                // 打开服务主机以侦听传入消息
                selfHost.Open();
                Console.WriteLine("The service is ready.");

                // Close the ServiceHost to stop the service.
                Console.WriteLine("Press <Enter> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();
                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                selfHost.Abort();
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Attempts to create the named pipe service.
        /// </summary>
        /// <param name="uid">The application's unique identifier.</param>
        /// <returns>True if the service was published successfully.</returns>
        private static bool OpenServiceHost(string uid)
        {
            try
            {
                //hook the application exit event to avoid race condition when messages flow while the application is disposing of the channel during shutdown
                Application.Current.Exit += new ExitEventHandler(OnAppExit);

                //for any unhandled exception we need to ensure NamedPipeHost is disposed
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);


                //setup the WCF service using a NamedPipe
                NamedPipeHost = new ServiceHost(typeof(SingleInstance), new Uri("net.pipe://localhost/7thHeavenApp"));
                NamedPipeHost.AddServiceEndpoint(typeof(ISingleInstance), new NetNamedPipeBinding(), uid);

                //if the service is already open (i.e. another instance is already running) this will cause an exception
                NamedPipeHost.Open();

                //success and we are first instance
                return(true);
            }
            catch (AddressAlreadyInUseException)
            {
                //failed to open the service so must be a second instance
                NamedPipeHost.Abort();
                NamedPipeHost = null;
                return(false);
            }
            catch (CommunicationObjectFaultedException)
            {
                //failed to open the service so must be a second instance
                NamedPipeHost.Abort();
                NamedPipeHost = null;
                return(false);
            }
            catch (Exception)
            {
                // an uknown error occurred maybe invalid endpoint?
                return(false);
            }
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            Uri               baseAddress1 = new Uri("http://localhost:10003/my");
            Uri               baseAddress2 = new Uri("http://localhost:20003");
            ServiceHost       mojHost1     = new ServiceHost(typeof(MojSerwis), baseAddress1);
            ServiceHost       mojHost2     = new ServiceHost(typeof(mojCallbackKalkulator), baseAddress2);
            WSHttpBinding     binding      = new WSHttpBinding();
            WSDualHttpBinding mojBanding2  = new WSDualHttpBinding();

            try
            {
                ServiceEndpoint endpoint1 = mojHost1.AddServiceEndpoint(typeof(ISerwis), binding, "e1");
                ServiceEndpoint endpoint2 = mojHost2.AddServiceEndpoint(typeof(ICallbackKalkulator), mojBanding2, "CallbackKalkulator");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                mojHost1.Description.Behaviors.Add(smb);

                ServiceMetadataBehavior smb2 = new ServiceMetadataBehavior();
                smb2.HttpGetEnabled = true;
                mojHost2.Description.Behaviors.Add(smb2);

                mojHost1.Open();
                Console.WriteLine("--->MojSerwis jest uruchomiony.");

                mojHost2.Open();
                Console.WriteLine("--->CallbackKalkulator uruchomiony.");

                Console.WriteLine("--->Nacisnij <ENTER> aby zakonczyc.\n");
                Console.ReadLine(); //czekam na zamkniecie
                mojHost1.Close();
                mojHost2.Close();
                Console.WriteLine("---> Serwis zakonczyl dzialanie.");
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("Wystapil wyjatek: {0}", ce.Message);
                mojHost1.Abort();
                mojHost2.Abort();
            }
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            // Tworzymy adres gdzie pod którym bedzie dostepna usługa
            int numberOfServer;

            Console.WriteLine("Podaj numer serwera");
            numberOfServer = Convert.ToInt32(Console.ReadLine());
            Uri baseAddress = new Uri("http://localhost:8000/MandelbrotCalcService" + numberOfServer.ToString() + "/");

            Console.WriteLine(baseAddress.ToString());

            // Tworzymy obiekt klasy CalculatorService
            ServiceHost selfHost = new ServiceHost(typeof(MandelbrotCalcService), baseAddress);

            try
            {
                // Dodajemy Endopoint usługi
                selfHost.AddServiceEndpoint(typeof(IMandelbrotCalc), new BasicHttpBinding(), "MandelbrotCalcService");

                // Umozliwiamy wymiane metadanych
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                // Startujemy serwis
                selfHost.Open();
                Console.WriteLine("Serwis działa....");
                Console.WriteLine("Nacisnij <ENTER> by zakonczyc.");
                Console.WriteLine();
                Console.ReadLine();

                // zamykamy serwis
                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("Przechwyciłem wyjatek: {0}", ce.Message);
                selfHost.Abort();
                Console.ReadLine();
            }
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            Uri           baseAddress1 = new Uri("http://localhost:10216/serwis1");
            ServiceHost   mojHost1     = new ServiceHost(typeof(MojSerwis), baseAddress1);
            WSHttpBinding binding1     = new WSHttpBinding();

            Uri               baseAddress2 = new Uri("http://localhost:20216/serwis2");
            ServiceHost       mojHost2     = new ServiceHost(typeof(mojCallbackKalkulator), baseAddress2);
            WSDualHttpBinding binding2     = new WSDualHttpBinding();

            try
            {
                ServiceEndpoint endpoint1 = mojHost1.AddServiceEndpoint(typeof(ISerwis), binding1, "endpoint1");
                ServiceEndpoint endpoint2 = mojHost2.AddServiceEndpoint(typeof(ICallbackKalkulator),
                                                                        binding2, "CallbackKalkulator");
                ServiceMetadataBehavior smb  = new ServiceMetadataBehavior();
                ServiceMetadataBehavior smb2 = new ServiceMetadataBehavior();

                smb.HttpGetEnabled  = true;
                smb2.HttpGetEnabled = true;

                mojHost1.Description.Behaviors.Add(smb);
                mojHost2.Description.Behaviors.Add(smb2);

                mojHost1.Open();
                mojHost2.Open();

                Console.WriteLine("--->MojSerwis jest uruchomiony.");
                Console.WriteLine("--->CallbackKalkulator jest uruchomiony.");
                Console.WriteLine("--->Wcisnij ENTER aby zakonczyc.\n");
                Console.ReadLine();
                mojHost1.Close();
                mojHost2.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("Wystapil wyjatek {0}", ce);
                mojHost1.Abort();
                mojHost2.Abort();
            }
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            Console.Title = "C# Project Duplex Service Host";

            // Step 1 Create a URI to serve as the base address.
            // Ex. "http://localhost:9001/WCFServices/"
            var baseAddress = new Uri("http://localhost:9001/WCFServices/");

            // Step 2 Create a ServiceHost instance
            ServiceHost selfHost = new ServiceHost(typeof(WcfDuplexService), baseAddress);

            try
            {
                // Step 3 Add a service endpoint.
                selfHost.AddServiceEndpoint(typeof(IDuplexService),
                                            new WSDualHttpBinding(WSDualHttpSecurityMode.None), "NBADuplexService");

                // Step 4 Enable Metadata Exchange and Add MEX endpoint
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);
                selfHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(), baseAddress + "mex");

                // Step 5 Start the service.
                selfHost.Open();
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Listening at: {0}", baseAddress);
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                // Close the ServiceHostBase to shutdown the service.
                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                selfHost.Abort();
            }
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            _server = new DirectResponseWebService();
            using (ServiceHost serviceHost = new ServiceHost(_server))
            {
                try
                {
                    serviceHost.Open();
                    Console.WriteLine("Service is running");
                    Console.WriteLine("Press <Enter> to shutdown service");
                    Console.ReadLine();

                    serviceHost.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception: {0}", e.Message);
                    serviceHost.Abort();
                }
            }
        }
Exemplo n.º 29
0
        static void Main()
        {
            using (var host = new ServiceHost(typeof(MensageriaService)))
            {
                host.Faulted += Faulted;
                host.Open();

                Console.WriteLine("Serviço iniciado ...");

                Console.ReadLine();

                if (host != null)
                {
                    if (host.State == CommunicationState.Faulted)
                    {
                        host.Abort();
                    }
                    host.Close();
                }
            }
        }
Exemplo n.º 30
0
        private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            // остановка потока для обмена данными со схемой
            if (schemeExThread != null)
            {
                schemeExThread.Abort();
            }

            // остановка WCF-служб
            if (schemeSvcHost != null)
            {
                try { schemeSvcHost.Close(); }
                catch { schemeSvcHost.Abort(); }
            }

            if (domainSvcHost != null)
            {
                try { domainSvcHost.Close(); }
                catch { domainSvcHost.Abort(); }
            }
        }
Exemplo n.º 31
0
        public async Task StopAsync()
        {
            var wcfRequestSuccessful = false;

            try
            {
                if (_serviceHost.State != CommunicationState.Faulted)
                {
                    await Task.Factory.FromAsync(_serviceHost.BeginClose, _serviceHost.EndClose, null);

                    wcfRequestSuccessful = true;
                }
            }
            finally
            {
                if (!wcfRequestSuccessful)
                {
                    _serviceHost.Abort();
                }
            }
        }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            //vamos deixar o serviço online usando essa console application
            ServiceHost host     = new ServiceHost(typeof(JogadorService));
            Uri         endereco = new Uri("http://localhost:8080/jogadores");

            host.AddServiceEndpoint(typeof(IJogadorService), new BasicHttpBinding(), endereco);
            try
            {
                host.Open();
                ExibeInformacoes(host);
                Console.ReadLine();
                host.Close();
            }
            catch (Exception e)
            {
                host.Abort();
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
Exemplo n.º 33
0
		static void Main( string[] args )
		{
			TextWriterTraceListener tr = new TextWriterTraceListener( System.Console.Out );
			Debug.Listeners.Add( tr ); Debug.AutoFlush = true; Debug.IndentSize = 3;
			ConsoleHelper.SetWindowPosition( 1, 32 * 12 + 30 );

			Console.WriteLine( "\n===== Press [Enter] to start the tests..." ); Console.ReadLine();

			Console.WriteLine( "\n===== Registering types for the WCF machinery ..." );
			KTypesWCF.AddType( typeof( CalendarDate ) );
			KTypesWCF.AddType( typeof( ClockTime ) );

			Console.WriteLine( "\n===== Starting the service host ..." );
			ServiceHost host = new ServiceHost( typeof( MyServer ) );
			host.Open();

			Console.WriteLine( "\n===== Press [Enter] to finish the service host ..." ); Console.ReadLine();
			try { host.Close( new TimeSpan( 0, 0, 5 ) ); }
			catch { host.Abort(); throw; }

			Console.WriteLine( "\n===== Press [Enter] to terminate program..." ); Console.ReadLine();
		}