Exemplo n.º 1
0
 public void StartSMSService()
 {
     try
     {
         string ipAddress   = GetIPAddress();
         Uri    baseAddress = new Uri(String.Format("http://{0}:54000/SMSService/", ipAddress));
         serviceHost = new WebServiceHost(typeof(RESTService), baseAddress);
         serviceHost.AddServiceEndpoint(typeof(IRESTService), new WebHttpBinding(), "");
         ServiceMetadataBehavior smb = new ServiceMetadataBehavior
         {
             HttpGetEnabled = true
         };
         serviceHost.Description.Behaviors.Add(smb);
         serviceHost.Description.Namespace = "http://SJBCS.SMS";
         serviceHost.Open();
         Logger.Info("SMS Service started");
     }
     catch (CommunicationException ce)
     {
         Logger.Error("Error encountered when starting SMS Service", ce);
         serviceHost.Abort();
     }
     catch (Exception e)
     {
         Logger.Error("Error encountered when starting SMS Service", e);
         serviceHost.Abort();
     }
 }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            var host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));

            try
            {
                host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");

                // BadCustomHelpPageWebHttpBehavior NOT INTENDED to use in real environment, added just for demonstration
                // Pass as an array of methods names to ignore in Help Page
                host.Description.Endpoints[0].Behaviors.Add(new BadCustomHelpPageWebHttpBehavior(new[] { "EchoWithGet" })
                {
                    HelpEnabled = true
                });

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

                host.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            bool           succeed = false;
            string         baseUri = "http://localhost:8081/NBTY";
            WebServiceHost sh      = new WebServiceHost(typeof(CatalogServiceType),
                                                        new Uri(baseUri));

            try
            {
                DataContractSerializer ser = new DataContractSerializer(typeof(CatalogServiceType));
                sh.Open();
                succeed = true;
                Console.WriteLine("Service is Running");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ServiceHost failed to open {0}", ex.ToString());
            }
            finally
            {
                //call Abort since the object will be in the Faulted state
                if (!succeed)
                {
                    sh.Abort();
                }
            }
        }
        public void Startup()
        {
            WebNotification.RestoreSubscriptions();

            Uri uri = new Uri("http://0.0.0.0:" + Global.webapi_port + "/");

            host = new WebServiceHost(typeof(OmniLinkService), uri);

            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IOmniLinkService), new WebHttpBinding(), "");
                host.Open();

                log.Info("Listening on " + uri.ToString());
            }
            catch (CommunicationException ex)
            {
                log.Error("An exception occurred starting web service", ex);
                host.Abort();
            }

            // Wait until shutdown
            trigger.WaitOne();

            if (host != null)
            {
                host.Close();
            }

            WebNotification.SaveSubscriptions();
        }
Exemplo n.º 5
0
         static void Main(string[] args)
         {
 
             // Step 1 Add a service endpoint.
             using (WebServiceHost selfHost = new WebServiceHost(typeof(Service1)))
             {
                 try
                 {
                    // Step 2 Start the service.
                    selfHost.Open();
                    Console.WriteLine("The service is ready.");
                    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.º 6
0
        static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(LocalService), new Uri("http://localhost:8000/"));

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

                    ILocalService channel = cf.CreateChannel();
                }
                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();

                host.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }
Exemplo n.º 7
0
        private bool SetupWebService()
        {
            Uri webServiceAddress = new Uri("http://localhost:" + WCFPort.ToString() + "/SEServerExtender/Web/");

            m_webHost = new WebServiceHost(typeof(WebService), webServiceAddress);
            try
            {
                //WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
                //binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
                //binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                //ServiceEndpoint endpoint = m_webHost.AddServiceEndpoint(typeof(IWebServiceContract), binding, "WebService");
                //m_webHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
                //m_webHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new UserNameValidator();
                EnableCorsBehavior ecb = new EnableCorsBehavior();
                m_webHost.Description.Behaviors.Add(ecb);
                m_webHost.Open();
            }
            catch (CommunicationException ex)
            {
                Console.WriteLine("An exception occurred: {0}", ex.Message);
                m_webHost.Abort();
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        private void btnStart_Click(object sender, System.EventArgs e)
        {
            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
                host.Open();
                using (ChannelFactory <IService> cf = new ChannelFactory <IService>(new WebHttpBinding(), hostUri))
                {
                    cf.Endpoint.Behaviors.Add(new WebHttpBehavior());

                    IService channel = cf.CreateChannel();

                    WriteLine("Calling Start via HTTP GET: ");
                    int s = channel.Start(new StartRequest
                    {
                        MaxTurns  = 10,
                        GridSize  = "H8",
                        Players   = new[] { "Player1", "Player2" },
                        Ships     = new[] { "Carrier", "Destroyer" },
                        MineCount = 5
                    });

                    WriteLine("Output: {0}", s);
                }

                host.Close();
            }
            catch (CommunicationException cex)
            {
                WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            string URL = "http://localhost:8080/";

            Console.WriteLine("Starting service...");
            WebServiceHost serviceHandle = new WebServiceHost(typeof(WindowsSampleService), new Uri(URL));

            Console.WriteLine("Created service host handle.");
            try
            {
                serviceHandle.AddServiceEndpoint(typeof(IWindowsSampleService), new WebHttpBinding(), "");
                Console.WriteLine("Added service endpoint [" + URL + "].");
                serviceHandle.Open();
                Console.WriteLine("Opened the service endpoint.");
                using (ChannelFactory <IWindowsSampleService> bindingHandle = new ChannelFactory <IWindowsSampleService>(new WebHttpBinding(), URL))
                {
                    Console.WriteLine("Created a binding for service.");
                    bindingHandle.Endpoint.Behaviors.Add(new WebHttpBehavior());
                    Console.WriteLine("Configured service binding to use HTTP.");
                    IWindowsSampleService channel = bindingHandle.CreateChannel();
                    Console.WriteLine("Access service using URL in browser: <" + URL + "ShowMsgGet?s=TEXT_TO_BE_SHOWN>");
                }
                Console.WriteLine("Hit <ENTER> to quit");
                Console.ReadLine();

                serviceHandle.Close();
                Console.WriteLine("Stopped service.");
            }
            catch (CommunicationException exObj)
            {
                Console.WriteLine("{0}", exObj.Message);
                serviceHandle.Abort();
            }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            using (WebServiceHost host = new WebServiceHost(
                       typeof(TransfertService),
                       new Uri("http://localhost:8733/Bolywood/Service")
                       ))
            {
                try
                {
                    ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IDataContract), new WebHttpBinding(), "");
                    host.Open();

                    Console.WriteLine("The service is ready");

                    Console.WriteLine("Press <Enter> to stop the service.");
                    Console.Read();

                    // Close the ServiceHost.
                    //host.Close();
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine("An exception occurred: {0}", ce.Message);
                    host.Abort();
                }
            }
        }
Exemplo n.º 11
0
        private static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            while (true)
            {
                var logger = new Logger();
                var host   = new WebServiceHost(typeof(ConvertService));
                try
                {
                    host.Open();
                    logger.Info("Service started.");
                    Console.ReadLine();

                    host.Close();
                }
                catch (CommunicationException cex)
                {
                    logger.Error("An exception occurred: {0}", cex.Message);
                    host.Abort();
                }
                finally
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }
        }
Exemplo n.º 12
0
        public static void Main(String[] args)
        {
            ServiceHost host =
                new WebServiceHost(typeof(Explorer), new Uri("http://localhost:8733/Design_Time_Addresses/AztechService/Service1/"));
            //flag to check if call to Open succeeded

            bool openSucceeded = false;

            try
            {
                host.Open();
                openSucceeded = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("ServiceHost failed to open {0}", ex.ToString());
            }
            finally
            { //call Abort since the object will be in the Faulted state
                if (!openSucceeded)
                {
                    host.Abort();
                }
            }
            if (openSucceeded)
            {
                Console.WriteLine("Service is running...");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Service failed to open");
            }
            Console.ReadKey();
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            // <Snippet6>
            Uri            baseAddress = new Uri("http://localhost:8000/BlogService");
            WebServiceHost svcHost     = new WebServiceHost(typeof(BlogService), baseAddress);

            // </Snippet6>

            try
            {
                // <Snippet8>
                svcHost.Open();
                Console.WriteLine("Service is running");

                XmlReader       reader = XmlReader.Create("http://localhost:8000/BlogService/GetBlog");
                SyndicationFeed feed   = SyndicationFeed.Load(reader);
                Console.WriteLine(feed.Title.Text);
                Console.WriteLine("Items:");
                foreach (SyndicationItem item in feed.Items)
                {
                    Console.WriteLine("Title: {0}", item.Title.Text);
                    Console.WriteLine("Summary: {0}", ((TextSyndicationContent)item.Summary).Text);
                }
                Console.WriteLine("Press <enter> to quit...");
                Console.ReadLine();
                svcHost.Close();
                // </Snippet8>
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                svcHost.Abort();
            }
        }
Exemplo n.º 14
0
 protected override void OnStop()
 {
     if (host != null)
     {
         host.Abort();
         host = null;
     }
 }
Exemplo n.º 15
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();
            }
        }
        public bool StartWebService(int servicePort)
        {
            string httpEndpoint = GetBaseAddress(servicePort);

            try
            {
                serviceHost = new WebServiceHost(this, new Uri(httpEndpoint));

                serviceHost.AddServiceEndpoint(
                    typeof(WCFServiceApi),
                    GetHttpBinding(),
                    string.Empty);

                serviceHost.Open();

                // Debug
                Console.WriteLine("Http WebService running");

                return(true);
            }
            catch (AddressAccessDeniedException accessex)
            {
                Console.WriteLine("This process needs to be initialized with ELEVATED Command Prompt. Exiting now...");
                serviceHost.Abort();

                return(false);
            }
            catch (AddressAlreadyInUseException addressex)
            {
                Console.WriteLine("Port {0} is already registered by another process.", servicePort);
                serviceHost.Abort();

                return(false);
            }
            catch (Exception e)
            {
                Console.WriteLine("Fatal exception encountered during Http Webservice initialization. Exception: {0}", e);
                serviceHost.Abort();

                return(false);
            }
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            /*WebServiceHost host = new WebServiceHost(typeof(InterBank.InterBankOps), new Uri("http://localhost:8000/");
             * host.Open();
             * Console.WriteLine("Service InterBank Active. Press <Enter> to close.");
             * Console.ReadLine();
             * host.Close();*/
            WebServiceHost host = new WebServiceHost(typeof(InterBank.InterBankOps), new Uri("http://localhost:8000/"));

            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(InterBank.IInterBankOps), new WebHttpBinding(), "");
                host.Open();/*
                             * using (ChannelFactory<InterBank.IInterBankOps> cf = new ChannelFactory<InterBank.IInterBankOps>(new WebHttpBinding(), "http://localhost:8000"))
                             * {
                             * cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
                             *
                             * InterBank.IInterBankOps 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);
                             * Console.WriteLine("");
                             * }
                             */
                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();
                host.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
            finally
            {
                host.Close();
            }
        }
Exemplo n.º 18
0
 public void StopSMSService()
 {
     try
     {
         serviceHost?.Close();
         Logger.Info("SMS Service stopped");
     }
     catch (Exception e)
     {
         Logger.Error("Error encountered when stopping SMS Service", e);
         serviceHost.Abort();
     }
 }
Exemplo n.º 19
0
        private void SimpleForm_Load(object sender, EventArgs e)
        {
            var host = new WebServiceHost(typeof(CertificateService), new Uri("http://localhost:8000/"));

            try
            {
                host.AddServiceEndpoint(typeof(ICertificateService), new WebHttpBinding(), "");
                host.Open();
            }
            catch (CommunicationException cex)
            {
                host.Abort();
                MessageBox.Show(cex.Message, "Exception occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 20
0
        public void CloseAPIService()
        {
            try
            {
                _apiServiceHost.Faulted -= APIServiceHost_Faulted;
                _apiServiceHost.Closing -= APIServiceHost_Closing;
                _apiServiceHost.Close();
            }
            catch
            {
                _apiServiceHost.Abort();
            }

            isRunning = false;
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            // <Snippet6>
            Uri            address = new Uri("http://localhost:8000/BlogService/");
            WebServiceHost svcHost = new WebServiceHost(typeof(BlogService), address);

            // </Snippet6>
            try
            {
                // <Snippet8>
                svcHost.Open();
                Console.WriteLine("Service is running");

                Console.WriteLine("Loading feed in Atom 1.0 format.");
                XmlReader       atomReader = XmlReader.Create("http://localhost:8000/BlogService/GetBlog?format=atom");
                SyndicationFeed atomFeed   = SyndicationFeed.Load(atomReader);
                Console.WriteLine(atomFeed.Title.Text);
                Console.WriteLine("Items:");
                foreach (SyndicationItem item in atomFeed.Items)
                {
                    Console.WriteLine("Title: {0}", item.Title.Text);
                    Console.WriteLine("Content: {0}", ((TextSyndicationContent)item.Content).Text);
                }

                Console.WriteLine("Loading feed in RSS 2.0 format.");
                XmlReader       rssReader = XmlReader.Create("http://localhost:8000/BlogService/GetBlog?format=rss");
                SyndicationFeed rssFeed   = SyndicationFeed.Load(rssReader);
                Console.WriteLine(rssFeed.Title.Text);
                Console.WriteLine("Items:");
                foreach (SyndicationItem item in rssFeed.Items)
                {
                    Console.WriteLine("Title: {0}", item.Title.Text);
                    // Notice we are using item.Summary here instead of item.Content. This is because
                    // of the differences between Atom 1.0 and RSS 2.0 specs.
                    Console.WriteLine("Content: {0}", ((TextSyndicationContent)item.Summary).Text);
                }

                Console.WriteLine("Press <ENTER> to quit...");
                Console.ReadLine();
                svcHost.Close();
                // </Snippet8>
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                svcHost.Abort();
            }
        }
Exemplo n.º 22
0
        public WCFServer(string uri)
        {
            var host = new WebServiceHost(typeof(WebService), new Uri(uri));

            try
            {
                var ep = host.AddServiceEndpoint(typeof(IWebService), CreateBinding(), "");
                host.Open();
                Console.WriteLine("WCF: OK");
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            var host = new WebServiceHost(typeof(EvalService));

            try
            {
                host.Open();
                Console.ReadLine();
                host.Close();
            }
            catch (Exception)
            {
                host.Abort();
                throw;
            }
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            //根据服务类,以及基地址来初始化一个服务宿主
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("Http://localhost:8000/"));

            try
            {
                //初始化服务终结点,切记绑定的协议为WebHttpBinding
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
                host.Open();
                using (ChannelFactory <IService> cf = new ChannelFactory <IService>(new WebHttpBinding(), "http://localhost:8000"))
                {
                    //添加一个服务的终结点行为---WebHttpBehavior实例
                    cf.Endpoint.EndpointBehaviors.Add(new WebHttpBehavior());
                    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);
                    Console.WriteLine("");

                    Console.WriteLine("Press <ENTER> to terminate");
                    Console.ReadLine();
                }
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
            finally
            {
                host.Close();
            }
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(EvalService));

            try
            {
                host.Open();
                PrintServiceInfo(host);
                Console.ReadLine();
                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                host.Abort();
            }
        }
Exemplo n.º 26
0
        static void HostWCFRESTService()
        {
            WebServiceHost ghost = new WebServiceHost(typeof(EmployeeDataService));

            try
            {
                ghost.Open();
                Console.WriteLine("Host is up and running. Press enter to shut down");
                Console.ReadLine();
                ghost.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                ghost.Abort();
            }
        }
Exemplo n.º 27
0
 public static void OpenConnection()
 {
     host = new WebServiceHost(typeof(Service), new Uri("http://127.0.0.1:8000/"));
     try
     {
         ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), string.Empty);
         host.Open();
         ChannelFactory <IService> cf = new ChannelFactory <IService>(new WebHttpBinding(), "http://127.0.0.1:8000");
         cf.Endpoint.EndpointBehaviors.Add(new WebHttpBehavior());
         IService channel = cf.CreateChannel();
     }
     catch (CommunicationException ex)
     {
         Console.WriteLine("An exception occurred: {0}", ex.Message);
         host.Abort();
     }
 }
Exemplo n.º 28
0
        public void Start()
        {
            bool openSucceeded = false;

            try {
                _serviceHost.Open();
                openSucceeded = true;
                logger.Info("Service is started.");
            } catch (Exception ex) {
                logger.ErrorFormat("Error caught from service host. {0}", ex);
            } finally {
                if (!openSucceeded)
                {
                    _serviceHost.Abort();
                }
            }
        }
Exemplo n.º 29
0
        private void CloseServiceHost()
        {
            if (_serviceHost == null)
            {
                return;
            }

            try
            {
                _serviceHost.Close();
            }
            catch (Exception)
            {
                _serviceHost.Abort();
            }

            _serviceHost = null;
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(
                typeof(EvalServiceLibrary.EvalService));

            try
            {
                host.Open();
                Console.WriteLine("Running");
                Console.ReadLine();
            }
            catch (Exception)
            {
                host.Abort();
                throw;
            }
            host.Close();
        }
Exemplo n.º 31
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();
                }
            }
        }