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


C# ServiceHost.Close方法代码示例

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


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

示例1: ShouldSetShieldingWithNonIncludeExceptionDetailInFaults

 public void ShouldSetShieldingWithNonIncludeExceptionDetailInFaults()
 {
     // create a mock service and its endpoint.
     Uri serviceUri = new Uri("http://tests:30003");
     ServiceHost host = new ServiceHost(typeof(MockService), serviceUri);
     host.AddServiceEndpoint(typeof(IMockService), new WSHttpBinding(), serviceUri);
     host.Open();
     try
     {
         // check that we have no ErrorHandler loaded into each channel that
         // has IncludeExceptionDetailInFaults turned off.
         foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
         {
             Assert.AreEqual(0, dispatcher.ErrorHandlers.Count);
             Assert.IsFalse(dispatcher.IncludeExceptionDetailInFaults);
         }
         ExceptionShieldingBehavior behavior = new ExceptionShieldingBehavior();
         behavior.ApplyDispatchBehavior(null, host);
         // check that the ExceptionShieldingErrorHandler was assigned to each channel
         foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
         {
             Assert.AreEqual(1, dispatcher.ErrorHandlers.Count);
             Assert.IsTrue(dispatcher.ErrorHandlers[0].GetType().IsAssignableFrom(typeof(ExceptionShieldingErrorHandler)));
         }
     }
     finally
     {
         if (host.State == CommunicationState.Opened)
         {
             host.Close();
         }
     }
 }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:33,代码来源:ExceptionShieldingBehaviorFixture.cs

示例2: StartServer

 /// <summary>
 /// Start the server
 /// </summary>
 /// <param name="address">the address that the server binds to</param>
 static void StartServer(string address)
 {
     ServiceHost host = null;
     try
     {
         NetTcpBinding tcpBinding = new NetTcpBinding();
         //set the maximum message size
         tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue;
         tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue;
         //start the service
         host = new ServiceHost(typeof(ATCMasterControllerImpl));
         host.AddServiceEndpoint(typeof(IATCMasterController), tcpBinding, "net.tcp://" + address);
         host.Open();
         System.Console.WriteLine("Press Enter to exit");
         //keep server running until enter is pressed
         System.Console.ReadLine();
         //exit
         host.Close();
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e.Message);
         if (host != null)
             host.Close();
         StartServer(address);
     }
 }
开发者ID:jasongi,项目名称:air-traffic-control-simulator,代码行数:31,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            ServiceHost condititionHost=null;
            ServiceHost moldpartInfoHost=null;
            ServiceHost storageHost=null;
            ServiceHost smartDeviceHost = null;
            ServiceHost restHost = null;

            try
            {
                condititionHost = new ServiceHost(typeof(ConditionService));
                moldpartInfoHost = new ServiceHost(typeof(MoldPartInfoService));
                storageHost = new ServiceHost(typeof(StorageManageService));
                smartDeviceHost = new ServiceHost(typeof(SmartDeviceApi));
                restHost = new ServiceHost(typeof(RestService));

                condititionHost.Open();
                moldpartInfoHost.Open();
                storageHost.Open();
                smartDeviceHost.Open();
                restHost.Open();
                Console.WriteLine("服务已经启动,请保持其运行...");
                Console.WriteLine("退出请按 Q ,并回车");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (condititionHost != null && condititionHost.State == CommunicationState.Opened)
                    condititionHost.Close();
                if (moldpartInfoHost != null && moldpartInfoHost.State == CommunicationState.Opened)
                    moldpartInfoHost.Close();
                if (storageHost != null && storageHost.State == CommunicationState.Opened)
                    storageHost.Close();
                if (smartDeviceHost != null && smartDeviceHost.State == CommunicationState.Opened)
                    smartDeviceHost.Close();
                if (restHost != null && restHost.State == CommunicationState.Opened)
                    restHost.Close();
            }
              string quit=Console.ReadLine();
              while (true)
              {
              if (quit.Equals("Q"))
              {
                  if (condititionHost != null && condititionHost.State == CommunicationState.Opened)
                      condititionHost.Close();
                  if (moldpartInfoHost != null && moldpartInfoHost.State == CommunicationState.Opened)
                      moldpartInfoHost.Close();
                  if (storageHost != null && storageHost.State == CommunicationState.Opened)
                      storageHost.Close();
                  if (smartDeviceHost != null && smartDeviceHost.State == CommunicationState.Opened)
                      smartDeviceHost.Close();
                  if (restHost != null && restHost.State == CommunicationState.Opened)
                      restHost.Close();
                  break;
              }
              quit = Console.ReadLine();
              }
        }
开发者ID:shentianyi,项目名称:MoldSmartDevice,代码行数:58,代码来源:Program.cs

示例4: RunServer

 private void RunServer()
 {
     try
     {
         using (ServiceHost host = new ServiceHost(typeof(WcfService)))
         {
             try
             {
                 ServiceDescription serviceDesciption = host.Description;
                 foreach (ServiceEndpoint endpoint in serviceDesciption.Endpoints)
                 {
                     string properties = "";
                     ConsoleColor oldColour = Console.ForegroundColor;
                     Console.ForegroundColor = ConsoleColor.Yellow;
                     properties = "Endpoint - address:  " + endpoint.Address + "\n";
                     properties += "         - binding name:\t\t" + endpoint.Binding.Name + "\n";
                     properties += "         - contract name:\t\t" + endpoint.Contract.Name + "\n";
                     Console.WriteLine("\n" + properties);
                     Console.WriteLine();
                     Console.ForegroundColor = oldColour;
                 }
                 host.Open();
                 Console.WriteLine("Server is running at " + DateTime.Now.ToString());
                 Console.ReadLine();
                 host.Close();
                 Console.WriteLine("Host is closed. Server is shutting down.");
             }
             catch (Exception e)
             {
                 Console.WriteLine("Fatal error: \n" + e.Message);
                 try
                 {
                     if (host != null)
                         host.Close();
                 }
                 catch
                 {
                     Console.WriteLine("Fatal error while closing host: \n" + e.Message);
                 }
                 Console.WriteLine("Press Enter to close application");
                 Console.ReadLine();
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Fatal error while creating new ServiceHost: \n" + e.Message);
         Console.WriteLine("Press Enter to close application");
         Console.ReadLine();
     }
 }
开发者ID:reaperdk,项目名称:timetracker,代码行数:51,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            //BaseAddress
            Uri baseAddress = new Uri("http://localhost:8080/SelfService.HarryPotter");

            //ServiceHost
            ServiceHost selfServiceHost = new ServiceHost(typeof(HarryPotterBooksCheckerService), baseAddress);
            try
            {
                //ABC-Endpoint
                selfServiceHost.AddServiceEndpoint(typeof(IHarryPotterBooks), new WSHttpBinding(), "HarryPotterCheckerService");

                ServiceMetadataBehavior smBehavior = new ServiceMetadataBehavior {HttpGetEnabled = true};
                selfServiceHost.Description.Behaviors.Add(smBehavior);

                selfServiceHost.Open();
                Console.WriteLine("Tjänsten är öppen");
                Console.ReadKey();

            }
            catch (CommunicationException ex)
            {
                selfServiceHost.Close();
                Console.WriteLine($"Ett kommunikationsfel har uppstått.: {ex.Message}");
                Console.ReadKey();
                throw;
            }
        }
开发者ID:Emmyandersson,项目名称:WCF,代码行数:28,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            //NetTcpBinding bind = new NetTcpBinding();
            //Uri uri = new Uri(ConfigurationManager.AppSettings["baseAddress"]);
            //ServiceHost host = new ServiceHost(typeof(QQServer.ChatService), uri);

            //if (host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
            //{
            //    BindingElement metaElement = new TcpTransportBindingElement();
            //    CustomBinding metaBind = new CustomBinding(metaElement);
            //    host.Description.Behaviors.Add(new System.ServiceModel.Description.ServiceMetadataBehavior());
            //    host.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), metaBind, "MEX");
            //}

            //host.Open();
            //Console.WriteLine("Chat service start to listen: endpoint {0}", uri.ToString());
            //Console.WriteLine("Press Enter to stop listen...");
            //Console.ReadLine();
            //host.Abort();
            //host.Close();

            using(ServiceHost host = new ServiceHost(typeof(QQServer.ChatService)))
            {
                host.Open();
                Console.WriteLine("Chat service start to listen: endpoint {0}", @"http://localhost:8732/QQServer/ChatService/");
                Console.WriteLine("Press Enter to stop listen...");
                Console.ReadLine();
                host.Close();
            }
        }
开发者ID:Yuanxiangz,项目名称:WorkSpace,代码行数:30,代码来源:Program.cs

示例7: Main

      static void Main()
      {
         if(MessageQueue.Exists(@".\private$\MyPersistentSubscriberQueue1") == false)
         {
            MessageQueue.Create(@".\private$\MyPersistentSubscriberQueue1",true);
         }
         if(MessageQueue.Exists(@".\private$\MyPersistentSubscriberQueue2") == false)
         {
            MessageQueue.Create(@".\private$\MyPersistentSubscriberQueue2",true);
         }
         if(MessageQueue.Exists(@".\private$\MyPersistentSubscriberQueue3") == false)
         {
            MessageQueue.Create(@".\private$\MyPersistentSubscriberQueue3",true);
         }
         ServiceHost host1 = new ServiceHost(typeof(MyPersistentSubscriber1),new Uri("http://localhost:7000/"));
         host1.Open();

         ServiceHost host2 = new ServiceHost(typeof(MyPersistentSubscriber2),new Uri("http://localhost:8000/"));
         host2.Open();

         ServiceHost host3 = new ServiceHost(typeof(MyPersistentSubscriber3),new Uri("http://localhost:9000/"));
         host3.Open();

         Application.Run(new HostForm());

         host1.Close();
         host2.Close();
         host3.Close();
      }
开发者ID:ssickles,项目名称:archive,代码行数:29,代码来源:Program.cs

示例8: Main

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

            ServiceHost selfHost = new ServiceHost(typeof(StringManipulatorService), baseAddress);

            try
            {
                selfHost.AddServiceEndpoint(
                    typeof(IStringManipulator),
                    new WSHttpBinding(),
                    "StringManipulatorService");

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

                // Step 5 of the hosting procedure: Start (and then stop) 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:danielglyde,项目名称:WCFStringManipulator,代码行数:34,代码来源:Program.cs

示例9: Main

        static void Main(string[] args)
        {
            // Create binding for the service endpoint.
            CustomBinding amqpBinding = new CustomBinding();
            amqpBinding.Elements.Add(new BinaryMessageEncodingBindingElement());
            amqpBinding.Elements.Add(new AmqpTransportBindingElement());

            // Create ServiceHost.
            ServiceHost serviceHost = new ServiceHost(typeof(HelloService), new Uri[] { new Uri("http://localhost:8080/HelloService2") });

            // Add behavior for our MEX endpoint.
            ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();
            mexBehavior.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(mexBehavior);

            // Add MEX endpoint.
            serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "MEX");

            // Add AMQP endpoint.
            Uri amqpUri = new Uri("amqp:news");
            serviceHost.AddServiceEndpoint(typeof(IHelloService), amqpBinding, amqpUri.ToString());

            serviceHost.Open();

            Console.WriteLine();
            Console.WriteLine("The consumer is now listening on the queue \"news\".");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.WriteLine();
            Console.ReadLine();

            if (serviceHost.State != CommunicationState.Faulted)
            {
                serviceHost.Close();
            }
        }
开发者ID:ncdc,项目名称:qpid,代码行数:35,代码来源:Another_Topic_Consumer.cs

示例10: Main

        static void Main(string[] args)
        {
            Uri address = new Uri("http://localhost:8080/Lab2.Service.Age");
            ServiceHost serviceHost = new ServiceHost(typeof(Days), address);
            try
            {
                serviceHost.AddServiceEndpoint(typeof(IDays),
                    new WSHttpBinding(),
                    "Days");
                ServiceMetadataBehavior smBehavior = new ServiceMetadataBehavior();
                smBehavior.HttpGetEnabled = true;
                serviceHost.Description.Behaviors.Add(smBehavior);

                serviceHost.Open();
                Console.WriteLine("Tjänsten är öppen!");
                Console.WriteLine("Tryck enter för att avsluta");
                Console.ReadLine();
            }
            catch (CommunicationException ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                throw;
            }
            finally
            {
                serviceHost.Close();
            }
        }
开发者ID:MartinaMagnusson,项目名称:WCF,代码行数:29,代码来源:Program.cs

示例11: Main

        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(ServiceA));
            host.Open();

            ServiceEndpointCollection endpoints = host.Description.Endpoints;
            foreach (ServiceEndpoint item in endpoints)
            {
                Console.WriteLine(item.Address);
            }

            ServiceHost host2 = new ServiceHost(typeof(ServiceA2));
            host2.Open();

            endpoints = host2.Description.Endpoints;
            foreach (ServiceEndpoint item in endpoints)
            {
                Console.WriteLine(item.Address);
            }

            Console.WriteLine();
            Console.WriteLine("Please press Enter to terminate the Host");
            Console.ReadLine();

            host.Close();
        }
开发者ID:ChuckTest,项目名称:WCFTest,代码行数:26,代码来源:Program.cs

示例12: Main

        static void Main(string[] args)
        {
            // Create service host
            ServiceHost sh = new ServiceHost(typeof(CalculatorService));

            // Setting the certificateValidationMode to PeerOrChainTrust means that if the certificate
            // is in the user's Trusted People store, then it will be trusted without performing a
            // validation of the certificate's issuer chain. This setting is used here for convenience so that the
            // sample can be run without having to have certificates issued by a certificate authority (CA).
            // This setting is less secure than the default, ChainTrust. The security implications of this
            // setting should be carefully considered before using PeerOrChainTrust in production code.
            sh.Credentials.IssuedTokenAuthentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;
            sh.Open();

            try
            {
                foreach (ChannelDispatcher cd in sh.ChannelDispatchers)
                    foreach (EndpointDispatcher ed in cd.Endpoints)
                        Console.WriteLine("Service listening at {0}", ed.EndpointAddress.Uri);

                Console.WriteLine("Press enter to close the service");
                Console.ReadLine();
            }
            finally
            {
                sh.Close();
            }
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:28,代码来源:Service.cs

示例13: Main

        static void Main(string[] args)
        {
            using (var host = new ServiceHost(typeof(RExService.RExService) ))//, new Uri("http://localhost:5555")))
            {
                try
                {
                    /*
                    host.AddServiceEndpoint(typeof(IRExService), new WSHttpBinding(), "");
                    var smb = new ServiceMetadataBehavior();
                    smb.HttpGetEnabled = true;
                    host.Description.Behaviors.Add(smb);
                    */

                    host.Open();

                    Console.WriteLine("Service started at {0}", host.BaseAddresses.First());
                    Console.WriteLine("Press <ENTER> to terminate...");
                    Console.WriteLine();
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    Console.WriteLine();
                }
                finally
                {
                    host.Close();
                }
            }
        }
开发者ID:kbochenina,项目名称:Kraken,代码行数:32,代码来源:Program.cs

示例14: Main

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

           
            ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);

            try
            {
             
                selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");

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

                selfHost.Open();
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();
                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                selfHost.Abort();
            }
        }
开发者ID:Leifsgard,项目名称:Labb2,代码行数:31,代码来源:Program.cs

示例15: RunForm

 public void RunForm()
 {
     ServiceHost host = new ServiceHost(typeof(Service.StationService));
     host.Open();
     Application.Run(new FormHidden());
     host.Close();
 }
开发者ID:w01f,项目名称:VolgaTeam.ProgramManager,代码行数:7,代码来源:AppManager.cs


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