Exemplo n.º 1
0
        public void ServiceBaseUriTest()
        {
            var host = new WebServiceHost(typeof(MyService), new Uri("http://" + NetworkHelpers.LocalEphemeralEndPoint().ToString()));

            Assert.AreEqual(0, host.Description.Endpoints.Count, "no endpoints yet");
            host.Open();
            Assert.AreEqual(1, host.Description.Endpoints.Count, "default endpoint after open");
            host.Close();
        }
Exemplo n.º 2
0
        public void ServiceBaseUriTest()
        {
            var host = new WebServiceHost(typeof(MyService), new Uri("http://localhost:8080/"));

            Assert.AreEqual(0, host.Description.Endpoints.Count, "no endpoints yet");
            host.Open();
            Assert.AreEqual(1, host.Description.Endpoints.Count, "default endpoint after open");
            host.Close();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            RestGameServices gameServices = new RestGameServices();
            WebServiceHost   serviceHost  = new WebServiceHost(gameServices, new Uri("http://localhost:8000/RandomSpaiceShip"));

            serviceHost.Open();
            Console.ReadKey();
            serviceHost.Close();
        }
Exemplo n.º 4
0
 public void Close()
 {
     if (host != null && Connected)
     {
         host.Close();
         host      = null;
         Connected = false;
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Close the service host.
        /// </summary>
        protected void CloseHost()
        {
            if (_serviceHost != null)
            {
                _serviceHost.Close();
            }

            _serviceHost = null;
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            RestDemoService demoServices = new RestDemoService();
            WebServiceHost  _serviceHost = new WebServiceHost(demoServices, new Uri("http://localhost:10000/DemoService"));

            _serviceHost.Open();
            Console.ReadKey();
            _serviceHost.Close();
        }
Exemplo n.º 7
0
 private void StopHealthCheckMonitor()
 {
     _healthCheckServiceHost.Close();
     if (serviceHost != null)
     {
         serviceHost.Close();
         serviceHost = null;
     }
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            // <Snippet2>
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));

            // </Snippet2>
            try
            {
                // <Snippet3>
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
                // </Snippet3>
                host.Open();
                // <Snippet6>
                using (ChannelFactory <IService> cf = new ChannelFactory <IService>(new WebHttpBinding(), "http://localhost:8000"))
                // </Snippet6>
                {
                    // <Snippet7>
                    cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
                    // </Snippet7>

                    // <Snippet8>
                    IService channel = cf.CreateChannel();

                    string s;

                    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
                    s = channel.EchoWithGet("Hello, world");
                    Console.WriteLine("   Output: {0}", s);

                    Console.WriteLine("");
                    Console.WriteLine("This can also be accomplished by navigating to");
                    Console.WriteLine("http://localhost:8000/EchoWithGet?s=Hello, world!");
                    Console.WriteLine("in a web browser while this sample is running.");

                    Console.WriteLine("");

                    Console.WriteLine("Calling EchoWithPost via HTTP POST: ");
                    s = channel.EchoWithPost("Hello, world");
                    Console.WriteLine("   Output: {0}", s);
                    // </Snippet8>
                    Console.WriteLine("");
                }

                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();

                // <Snippet9>
                host.Close();
                // </Snippet9>
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var serviceHost = new WebServiceHost(typeof(Machine), new Uri("http://localhost:8080/wcf"));

            serviceHost.Open();

            Console.WriteLine("your service is starting...");
            Console.ReadLine();
            serviceHost.Close();
        }
Exemplo n.º 10
0
 public override void Stop()
 {
     if (_host != null)
     {
         Log("Stopping Service");
         _host.Close();
         _host = null;
     }
     Running = false;
 }
Exemplo n.º 11
0
 private void frmFingerPrintClockServer_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         FingerPrintClockServiceHost.Close();
     }
     catch
     {
     }
 }
Exemplo n.º 12
0
 private void btnClose_Click(object sender, EventArgs e)
 {
     if (host != null)
     {
         host.Close();
         host                  = null;
         this.label1.Text      = "Service Closed";
         this.btnStart.Enabled = true;
     }
 }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            WebServiceHost wh = new WebServiceHost(typeof(HelloWorldService), new Uri(ServiceUri));

            wh.Open();
            Console.WriteLine("Service opened on {0}", ServiceUri);
            Console.WriteLine("Press any key to stop service...");
            Console.ReadKey();
            wh.Close();
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            var serviceHost = new WebServiceHost(typeof(ReviewApi));

            serviceHost.Open();

            Console.WriteLine("HTTP Service is running. Press any key to quit...");
            Console.ReadKey();
            serviceHost.Close();
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            var host     = new WebServiceHost(typeof(MyService), new Uri("http://localhost:80/"));
            var endpoint = host.AddServiceEndpoint(typeof(IMyService), new WebHttpBinding(), "");

            host.Open();
            Console.WriteLine("Return to quit...");
            Console.ReadLine();
            host.Close();
        }
Exemplo n.º 16
0
 private static void Main()
 {
     BindRequestToProcessors();
     _service = new WebServiceHost(typeof(JsonServicePerCall));
     _service.Open();
     Console.WriteLine("Sample REST Service is running");
     Console.WriteLine("Press any key to exit\n");
     Console.ReadKey();
     _service.Close();
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            Service        myService     = new Service();
            WebServiceHost myServiceHost = new WebServiceHost(myService, ServiceUri);

            myServiceHost.Open();
            Console.WriteLine("Service is running...");
            Console.ReadKey();
            myServiceHost.Close();
        }
Exemplo n.º 18
0
 static void Main()
 {
     using (var hostRestService = new WebServiceHost(typeof(CustomerRestService)))
     {
         hostRestService.Open();
         Console.WriteLine("Service is running");
         Console.ReadLine();
         hostRestService.Close();
     }
 }
Exemplo n.º 19
0
        static void Main()
        {
            WebServiceHost host = new WebServiceHost(typeof(TTService.TTService));

            host.Open();
            Console.WriteLine("TT service running");
            Console.WriteLine("Press ENTER to stop the service");
            Console.ReadLine();
            host.Close();
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            StudentScoreQueryService service      = new StudentScoreQueryService();
            WebServiceHost           _serviceHost = new WebServiceHost(service, new Uri("http://127.0.0.1:8899/Demo"));

            _serviceHost.Open();
            Console.WriteLine("输入任意键关闭程序!");
            Console.ReadKey();
            _serviceHost.Close();
        }
Exemplo n.º 21
0
 private static void Main()
 {
     ConfigureService();
     _service = new WebServiceHost(typeof(JsonServicePerCall));
     _service.Open();
     Console.WriteLine("REST Service is running");
     Console.WriteLine("Press any key to exit\n");
     Console.ReadKey();
     _service.Close();
 }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            RestServices   service      = new RestServices();
            WebServiceHost _serviceHost = new WebServiceHost(service, new Uri("http://localhost:8000/BarcodeService"));

            _serviceHost.Open();
            Console.Write("服务端正在监听8000端口......");
            Console.ReadKey();
            _serviceHost.Close();
        }
Exemplo n.º 23
0
        static void Main()
        {
            // For a REST WCF service host notice the use of WebServiceHost class instead of ServiceHost
            WebServiceHost host = new WebServiceHost(typeof(TTService.TTService));

            host.Open();
            Console.WriteLine("TT service running");
            Console.WriteLine("Press ENTER to stop the service");
            Console.ReadLine();
            host.Close();
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            WebServiceHost MyServiceHost = new WebServiceHost(typeof(Chapter7.WCFWebService.Service1), new Uri("http://localhost:8888/Test"));

            MyServiceHost.Open();


            Console.WriteLine("Service running...");
            Console.ReadLine();
            MyServiceHost.Close();
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            WebService     DemoServices = new WebService();
            WebHttpBinding binding      = new WebHttpBinding();
            WebServiceHost serviceHost  = new WebServiceHost(DemoServices, new Uri("http://localhost:8000/"));

            serviceHost.AddServiceEndpoint(typeof(IWebService), binding, "");
            serviceHost.Open();
            Console.ReadKey();
            serviceHost.Close();
        }
        public void should_add_the_servicebehavior_to_the_behavior_collection()
        {
            var host =
                new WebServiceHost(typeof(FakeService), new[] { new Uri("net.tcp://localhost:8081") });

            host.AddServiceEndpoint(typeof(IFakeService), new NetTcpBinding(), "net.tcp://localhost:8081/MyService");
            host.Open();

            host.Description.Behaviors.ShouldContainType<ServiceBehavior>();
            host.Close();
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            ServiceHost host = new WebServiceHost(typeof(PictureService), new Uri("http://localhost:9000/pictures"));

            host.Open();

            Console.WriteLine("Service Ready ...");
            Console.ReadLine();

            host.Close();
        }
Exemplo n.º 28
0
 private static void Main(string[] args)
 {
     using (var host = new WebServiceHost(typeof(RequestProcessor)))
     {
         host.Open();
         Console.WriteLine("Service is running");
         Console.WriteLine("Press enter to quit...");
         Console.ReadLine();
         host.Close();
     }
 }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(Service.MVCServices));

            host.Open();
            Console.WriteLine("Host started @ " + DateTime.Now.ToString());
            Update();
            DisplayHost(host);
            Console.ReadLine();
            host.Close();
        }
Exemplo n.º 30
0
        public static void Main(string[] args)
        {
            var host = new WebServiceHost(typeof(MagazineService.MagazineService));

            host.Open();

            Console.WriteLine("START");
            Console.ReadLine();

            host.Close();
        }
 public void StopWebService()
 {
     try
     {
         host.Close();
         Console.WriteLine("Service is closed correctly");
     }
     catch
     {
         Console.WriteLine("Couldn't stop service");
     }
 }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            string uriBaseAddress = args[0];
            string waitHandleName = null;
            if(args.Length > 1)
                 waitHandleName = args[1];

            Uri[] uriArray = { new Uri(uriBaseAddress) };

            Type serviceType = Assembly.GetExecutingAssembly().GetTypes().Single(t => !t.IsAbstract && typeof(Microsoft.OData.Service.IRequestHandler).IsAssignableFrom(t));

            using(WebServiceHost host = new WebServiceHost(serviceType, uriArray))
            {
                try
                {    
                    host.Open();
                    if(waitHandleName == "Debug" || string.IsNullOrEmpty(waitHandleName)) 
                    { 
                        Console.WriteLine("Running in Debug mode , please press any key to exit");
                        Console.Read();
                    }
                    else
                    {
                        EventWaitHandle waitHandle = EventWaitHandle.OpenExisting(waitHandleName);
                        waitHandle.WaitOne();
                    }
                    host.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An exception occurred:");
                    Console.WriteLine(ex.ToString());
                    host.Abort();
                    Console.ReadLine();
                }
            }
        }
Exemplo n.º 33
0
        public int StartProcess()
        {
            int result = 1;
              #region Pobranie i walidacja konfiguracji procesu

              ITNWebServiceCfgNode config = ITNWebServiceCfgHelper.GetITNWebServiceCfg(core.ProcessConfigurationXml);

              if (String.IsNullOrEmpty(config.endpointAddress.Trim()))
            throw new Exception("Processing canceled - endpoint address empty.");

              #endregion Pobranie i walidacja konfiguracji procesu
              SqlDatabase dbPTRConfig = null;
              TaskInserter.core = core;
              TaskInserter.dbPTRConfig = ConverterUtils.GetDBConfig(core);
              TaskInserter.taskId = config.graphBeginNodeId;
              TaskInserter.runningTaskId = TaskInserter.lastRunningTaskId = ConverterUtils.GetRunningTaskId(core);
              TaskInserter.connectionString = ConverterUtils.GetDBConvertersConnectionString(core);
              if(config.longTimer<= config.shortTimer)
              {
            throw new Exception("Processing canceled - maximum delay is shorter than task delay.");
              }
              else if(config.shortTimer == 0)
              {
            throw new Exception("Processing canceled - delay cannot be zero.");
              }
              else if (config.longTimer == 0)
              {
            throw new Exception("Processing canceled - maximum delay cannot be zero.");
              }
              TaskInserter.shortTimer = new PtrTimer(TaskInserter.ShortTimerHandler, config.shortTimer * 1000);
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Task delay {0} seconds.", config.shortTimer);
              TaskInserter.longTimer = new PtrTimer(TaskInserter.LongTimerHandler, config.longTimer * 1000);
              PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Maximum delay {0} seconds.", config.longTimer);

              try
              {
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Start processing");

            PTR3Core.DB_POOL.InitMSSqlPool(core, "database-converters");

            String endpointAddress = config.endpointAddress;
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Endpoint address is {0}", config.endpointAddress);
            //endpointAddress = "http://localhost/ITNWebService"; //odkomentować przy testowaniu na lokalnym hoście
            string singleWsdl = ConfigXmlReader.XmlGetConfigParam(core, "single-wsdl");
            if (String.IsNullOrEmpty(singleWsdl))
              singleWsdl = ConfigXmlReader.XmlGetConfigParam(core.OptionalConfigurationXml, "single-wsdl");

            string locationWsdl = ConfigXmlReader.XmlGetConfigParam(core, "location-wsdl");
            if (String.IsNullOrEmpty(locationWsdl))
              locationWsdl = ConfigXmlReader.XmlGetConfigParam(core.OptionalConfigurationXml, "location-wsdl");

            Uri uri = new Uri(endpointAddress);

            if (uri.Scheme != "http")
            {
              throw new Exception("Endpoint address has wrong schema: " + uri.Scheme);
            }

            int start = Environment.TickCount;
            int i = 0;
            bool bWorking = true;

            WebServiceHost<ITNWebServiceContract> host = new WebServiceHost<ITNWebServiceContract>(endpointAddress);
            host.EnableMetadataExchange(true);
            ServiceEndpoint endpoint = host.AddServiceHttpEndpoint((Type)typeof(IITNWebServiceContract), "");
            if (singleWsdl == "1" || !String.IsNullOrEmpty(locationWsdl))
              endpoint.Behaviors.Add(new WCFExtras.Wsdl.WsdlExtensions(null
            , String.IsNullOrEmpty(locationWsdl) ? null : new Uri(locationWsdl)
            , singleWsdl == "1"));
            ServiceDebugBehavior behavior =
              host.Description.Behaviors.Find<ServiceDebugBehavior>();

            if(behavior != null)
            {
              behavior.IncludeExceptionDetailInFaults = true;
            }
            else
            {
              host.Description.Behaviors.Add(
              new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
            }
            host.Open();
            Thread.Sleep(500);
            if (dbPTRConfig == null)
              dbPTRConfig = ConverterUtils.GetDBConfig(core);
            while (PTR3Wrapper.ShouldClose() == 0 && PTR3Wrapper.ShouldSuspend() == 0 && host.State == CommunicationState.Opened && bWorking)
            {
              if ((i++ % 50) == 0)
              {
            //PTR3Core.LOG.Log(MsgStatusEnum.MS_Deb3, "Online wait processing...");

            bWorking = host.HeartBeat();
              }
              Thread.Sleep(100);
            }
            host.Close();
            Thread.Sleep(500);
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Info, "Finish processing");
              }
              catch (Exception ex)
              {
            result = 0;
            PTR3Core.LOG.Log(MsgStatusEnum.MS_Error, ex, "");
              }

              return result;
        }