当前位置: 首页>>代码示例>>C#>>正文


C# WebServiceHost.Abort方法代码示例

本文整理汇总了C#中System.ServiceModel.Web.WebServiceHost.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# WebServiceHost.Abort方法的具体用法?C# WebServiceHost.Abort怎么用?C# WebServiceHost.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceModel.Web.WebServiceHost的用法示例。


在下文中一共展示了WebServiceHost.Abort方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8000/");
            ServiceHost selfHost = new WebServiceHost(typeof(MonitorService), baseAddress);

            try
            {
                // Step 3 Add a service endpoint.
                var t = new WebHttpBinding();

                selfHost.AddServiceEndpoint(typeof(IMonitorService), t, "test");
                WebHttpBehavior whb = new WebHttpBehavior();

                // 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.");
                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();
            }
        }
开发者ID:Shamsterl,项目名称:SimpleSystemMonitor,代码行数:35,代码来源:Program.cs

示例2: Main

 static void Main(string[] args)
 {
     WebServiceHost webHost = null;
     try
     {
         webHost = new WebServiceHost(typeof(CarRentalService), new Uri("http://localhost:1234"));
         webHost.Open();
         Console.WriteLine("Web service host is open...");
         Console.ReadLine();
     }
     catch(Exception ex)
     {
         if (webHost != null) webHost.Abort();
         Console.WriteLine(ex.ToString());
     }
 }
开发者ID:WindowsCommunicationFoundation,项目名称:WCF4-,代码行数:16,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            var host = new WebServiceHost(typeof(RestService), new Uri(RestUri));
            try
            {
                host.AddServiceEndpoint(typeof(IRestService), new WebHttpBinding(), "");
                host.Open();

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

                host.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("An exception occurred: {0}", e.Message);
                host.Abort();
            }
        }
开发者ID:CodingJournal,项目名称:WcfWebApiRestExample,代码行数:19,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));
            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
                host.Open();
                using (ChannelFactory<IService> cf = new ChannelFactory<IService>(new WebHttpBinding(), "http://localhost:8000"))
                {
                    cf.Endpoint.Behaviors.Add(new WebHttpBehavior());

                    IService channel = cf.CreateChannel();

                    object 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();
            }
        }
开发者ID:cMenu,项目名称:cMenu.Server,代码行数:43,代码来源:Program.cs

示例5: Main

 static void Main(string[] args)
 {
     var host = new System.ServiceModel.Web.WebServiceHost(typeof(EvalService));
      try
      {
     host.Open();
     foreach (var endpoint in host.Description.Endpoints)
     {
        Console.WriteLine(endpoint.Address.ToString());
     }
     Console.WriteLine("EvalService is up and running");
     Console.ReadLine();
     host.Close();
      }
      catch (Exception e)
      {
     Console.WriteLine(e);
     host.Abort();
      }
 }
开发者ID:xujihui1985,项目名称:WCFFundamental,代码行数:20,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            var host = new WebServiceHost(typeof(EvalService));

            try
            {
                host.Open();

                PrintServiceInfo(host);

                Console.WriteLine();
                Console.WriteLine("Press [ENTER] to shutdown the server...");
                Console.ReadLine();

                host.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                host.Abort();
            }
        }
开发者ID:spolnik,项目名称:WCF_Samples,代码行数:22,代码来源:Program.cs

示例7: Main

        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:9876/");

            //WebServiceHost svcHost = new WebServiceHost(typeof(AATodo.CalcService), baseAddress);
            WebServiceHost svcHost = new WebServiceHost(new AATodoService(), baseAddress);

            try
            {
                svcHost.Open();

                Console.WriteLine("Service is running at " + baseAddress);
                Console.WriteLine("Press enter to quit...");
                Console.ReadLine();

                svcHost.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                svcHost.Abort();
            }
        }
开发者ID:asdeshmukh,项目名称:AATodo,代码行数:23,代码来源:Program.cs

示例8: TestService

        public TestService(Type serviceType)
        {
            for (int i = 0; i < 100; i++)
            {
                int hostId = Interlocked.Increment(ref s_lastHostId);
                _serviceUri = new Uri("http://" + Environment.MachineName + "/Temporary_Listen_Addresses/MongoTestService" + hostId.ToString() + "/");
                _host = new WebServiceHost(serviceType, _serviceUri);
                try
                {
                    _host.Open();
                    break;
                }
                catch (Exception)
                {
                    _host.Abort();
                    _host = null;
                }
            }

            if (_host == null)
            {
                throw new InvalidOperationException("Could not open a service even after 100 tries.");
            }
        }
开发者ID:victorantos,项目名称:MongOData,代码行数:24,代码来源:TestService.cs

示例9: SetupWebServiceSilverlight

		private bool SetupWebServiceSilverlight()
		{
			Uri webServiceAddress = new Uri("http://localhost:" + SLWCFPort.ToString() + "/");
			m_webHostSilverlight = new WebServiceHost(typeof(WebServiceSilverlight), webServiceAddress);
			try
			{
				WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
				ServiceEndpoint endpoint = m_webHostSilverlight.AddServiceEndpoint(typeof(IPolicyRetriever), binding, "");
				m_webHostSilverlight.SetEndpointAddress(endpoint, "");
				m_webHostSilverlight.Open();
			}
			catch (CommunicationException ex)
			{
				Console.WriteLine("An exception occurred: {0}", ex.Message);
				m_webHostSilverlight.Abort();
				return false;
			}

			return true;
		}
开发者ID:generalwrex,项目名称:SE-Community-Mod-API,代码行数:20,代码来源:Server.cs

示例10: SetupWebService

		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;
		}
开发者ID:generalwrex,项目名称:SE-Community-Mod-API,代码行数:25,代码来源:Server.cs

示例11: Main

 private static void Main(string[] args)
 {
     var address = new Uri("http://localhost:8000/FeedService/");
     var svcHost = new WebServiceHost(typeof (FeedService), address);
     try {
         svcHost.Open();
         Console.WriteLine("Service is running");
         Console.WriteLine("Open browser at http://localhost:8000/FeedService/GetFeeds?format={atom/rss}");
         Console.WriteLine("Press <ENTER> to quit...");
         Console.ReadLine();
         svcHost.Close();
     }
     catch (CommunicationException ce) {
         Console.WriteLine("An exception occurred: {0}", ce.Message);
         svcHost.Abort();
     }
 }
开发者ID:nXqd,项目名称:csharp_wcf-rss-creator,代码行数:17,代码来源:Program.cs


注:本文中的System.ServiceModel.Web.WebServiceHost.Abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。