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();
         }
     }
 }
 /// <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);
     }
 }
Пример #3
0
        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();
              }
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 protected override void OnPause()
 {
     try
     {
         _gameHost.Close();
     }
     catch (Exception e)
     {
         eventLog1.WriteEntry(e.StackTrace, EventLogEntryType.Error);
         _gameHost.Abort();
     }
     base.OnPause();
 }
Пример #5
0
 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();
     }
 }
Пример #6
0
        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();
            }
        }
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8773/BasicService");

            BasicHttpBinding binding = new BasicHttpBinding();

            binding.Name = "Basic_Binding";
            binding.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard;
            binding.Security.Mode = BasicHttpSecurityMode.None;

            using (ServiceHost host = new ServiceHost(typeof(BasicService), baseAddress))
            {
                host.AddServiceEndpoint(typeof(IBasicService), binding, "http://localhost:8773/BasicService/mex");
                // Enable metadata publishing.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);
                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                // Close the ServiceHost.
                host.Close();
            }
        }
Пример #8
0
        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();
            }
        }
Пример #9
0
		static void Main()
		{
			// только не null, ибо возникнет исключение
			//var baseAddress = new Uri("http://localhost:8002/MyService");
			var host = new ServiceHost(typeof(MyContractClient));//, baseAddress);

			host.Open();

			//var otherBaseAddress = new Uri("http://localhost:8001/");
			var otherHost = new ServiceHost(typeof(MyOtherContractClient));//, otherBaseAddress);
			var wsBinding = new BasicHttpBinding();
			var tcpBinding = new NetTcpBinding();
			otherHost.AddServiceEndpoint(typeof(IMyOtherContract), wsBinding, "http://localhost:8001/MyOtherService");
			otherHost.AddServiceEndpoint(typeof(IMyOtherContract), tcpBinding, "net.tcp://localhost:8003/MyOtherService");

			//AddHttpGetMetadata(otherHost);
			AddMexEndpointMetadata(otherHost);

			otherHost.Open();


			// you can access http://localhost:8002/MyService
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new Host());

			otherHost.Close();

			host.Close();

			// you can not access http://localhost:8002/MyService
		}
Пример #10
0
        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();
            }
        }
        public void Start()
        {
            _source = new CancellationTokenSource();
            var token = _source.Token;
            _listenerTask = new Task(() =>
            {
                BusListener.MessageReceivedEvent += (s, e) => Console.WriteLine("Received message at " + e.Endpoint + " of type " + e.MessageType);
                BusListener.MessageSentEvent += (s, e) => Console.WriteLine("Sent message " + e.MessageType);
                BusListener.BusStartedEvent += (s, e) => Console.WriteLine("Bus started " + e.Endpoint);
                BusListener.MessageExceptionEvent += (s, e) => Console.WriteLine("Exception with message " + e.Endpoint + " for type " + e.MessageType + " with value " + e.Exception);
                using (var host = new ServiceHost(_listener, new[] { new Uri("net.tcp://localhost:5050") }))
                {

                    host.AddServiceEndpoint(typeof(IBusListener), new NetTcpBinding(), "NServiceBus.Diagnostics");

                    host.Opened += (s, e) => Console.WriteLine("Listening for events...");
                    host.Closed += (s, e) => Console.WriteLine("Closed listening for events...");

                    host.Open();

                    while (!token.IsCancellationRequested) { }

                    host.Close();
                }
            }, token);

            _listenerTask.Start();
            _listenerTask.Wait(10000);

        }
Пример #12
0
 public void RunForm()
 {
     ServiceHost host = new ServiceHost(typeof(Service.StationService));
     host.Open();
     Application.Run(new FormHidden());
     host.Close();
 }
Пример #13
0
        private void Run()
        {
            Console.WriteLine("Run a ServiceHost via programmatic configuration...");
            Console.WriteLine();

            string baseAddress = "http://" + Environment.MachineName + ":8000/Service.svc";
            Console.WriteLine("BaseAddress: {0}", baseAddress);

            using (ServiceHost serviceHost = new ServiceHost(typeof(Service)))
            {
                Console.WriteLine("Opening the host");
                serviceHost.Open();

                try
                {
                    var service = new Service();
                    Console.WriteLine(service);
                    Console.WriteLine("The service is ready.");
                    Console.WriteLine("Press <ENTER> to terminate service.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error on initializing the service host.");
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine();
                Console.ReadLine();
                serviceHost.Close();
            }
        }
Пример #14
0
        public static void Main()
        {
            var baseAddress = new Uri("http://localhost:3370/");

            // Create the ServiceHost.
            using (var host = new ServiceHost(typeof(Service), baseAddress))
            {
                // Enable metadata publishing.
                //var smb = new ServiceMetadataBehavior
                //{
                //    HttpGetEnabled = true,
                //    MetadataExporter = {PolicyVersion = PolicyVersion.Policy15}
                //};

                //host.Description.Behaviors.Add(smb);

                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                host.Close();
            }
        }
Пример #15
0
        static void Main(string[] args)
        {
            Console.Write("Your Service Namespace: ");
            string serviceNamespace = Console.ReadLine();
            Console.Write("Your Issuer Name: ");
            string issuerName = Console.ReadLine();
            Console.Write("Your Issuer Secret: ");
            string issuerSecret = Console.ReadLine();

            TransportClientEndpointBehavior relayCredentials = new TransportClientEndpointBehavior();
            relayCredentials.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret);

            Uri address = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "CalculatorService");

            //ServiceHost host = new ServiceHost(typeof(CalculatorService));
            ServiceHost host = new ServiceHost(typeof(CalculatorService), address);
            host.Description.Endpoints[0].Behaviors.Add(relayCredentials);
            host.Open();

            Console.WriteLine("Service address: " + address);
            Console.WriteLine("Press [Enter] to exit");
            Console.ReadLine();

            host.Close();
        }
Пример #16
0
        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();
                }
            }
        }
Пример #17
0
        static void Main(string[] args)
        {
            Activity element = new ApprovalRouteAndExecute();

            WorkflowService shservice = new WorkflowService
            {
                Name = "ApprovalManager",
                ConfigurationName = "Microsoft.Samples.DocumentApprovalProcess.ApprovalManager.ApprovalManager",
                Body = element
            };

            // Cleanup old table of users from previous run
            UserManager.DeleteAllUsers();

            ServiceHost sh = new ServiceHost(typeof(Microsoft.Samples.DocumentApprovalProcess.ApprovalManager.SubscriptionManager), new Uri("http://localhost:8732/Design_Time_Addresses/service/SubscriptionManager/"));
            sh.Open();

            System.ServiceModel.Activities.WorkflowServiceHost wsh = new System.ServiceModel.Activities.WorkflowServiceHost(shservice, new Uri("http://localhost:8732/Design_TimeAddress/service/ApprovalManager"));

            // Setup persistence
            wsh.Description.Behaviors.Add(new SqlWorkflowInstanceStoreBehavior(ApprovalProcessDBConnectionString));
            WorkflowIdleBehavior wib = new WorkflowIdleBehavior();
            wib.TimeToUnload = new TimeSpan(0, 0, 2);
            wsh.Description.Behaviors.Add(wib);

            wsh.Open();

            Console.WriteLine("All services ready, press any key to close the services and exit.");

            Console.ReadLine();
            wsh.Close();
            sh.Close();
        }
Пример #18
0
	public static void Main ()
	{
		SymmetricSecurityBindingElement sbe =
			new SymmetricSecurityBindingElement ();
		sbe.ProtectionTokenParameters =
			new SslSecurityTokenParameters ();
		ServiceHost host = new ServiceHost (typeof (Foo));
		HttpTransportBindingElement hbe =
			new HttpTransportBindingElement ();
		CustomBinding binding = new CustomBinding (sbe, hbe);
		binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
		host.AddServiceEndpoint ("IFoo",
			binding, new Uri ("http://localhost:8080"));
		ServiceCredentials cred = new ServiceCredentials ();
		cred.SecureConversationAuthentication.SecurityStateEncoder =
			new MyEncoder ();
		cred.ServiceCertificate.Certificate =
			new X509Certificate2 ("test.pfx", "mono");
		cred.ClientCertificate.Authentication.CertificateValidationMode =
			X509CertificateValidationMode.None;
		host.Description.Behaviors.Add (cred);
		host.Description.Behaviors.Find<ServiceDebugBehavior> ()
			.IncludeExceptionDetailInFaults = true;
//		foreach (ServiceEndpoint se in host.Description.Endpoints)
//			se.Behaviors.Add (new StdErrInspectionBehavior ());
		ServiceMetadataBehavior smb = new ServiceMetadataBehavior ();
		smb.HttpGetEnabled = true;
		smb.HttpGetUrl = new Uri ("http://localhost:8080/wsdl");
		host.Description.Behaviors.Add (smb);
		host.Open ();
		Console.WriteLine ("Hit [CR] key to close ...");
		Console.ReadLine ();
		host.Close ();
	}
Пример #19
0
 static void Main(string[] args)
 {
     ServiceHost sh = new ServiceHost(typeof(Quiz.Service.WcfService.Service));
     sh.Open();
     Console.ReadLine();
     sh.Close();
 }
Пример #20
0
        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();
        }
Пример #21
0
        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();
            }
        }
Пример #22
0
        private void Run()
        {
            // Create a ServiceHost for the service type and use base address in the configuration file.
            using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
            {
                // Apply query string formatter
                foreach (ServiceEndpoint endpoint in serviceHost.Description.Endpoints)
                {
                    foreach (OperationDescription operationDescription in endpoint.Contract.Operations)
                    {
                        EnableHttpGetRequestsBehavior.ReplaceFormatterBehavior(operationDescription, endpoint.Address);
                    }
                }

                // Open the ServiceHost to create listeners and start listening for messages.
                serviceHost.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                serviceHost.Close();
            }
        }
Пример #23
0
        static void Main(string[] args)
        {
            try
            {
                Process thisProc = Process.GetCurrentProcess();
                if (Process.GetProcessesByName(thisProc.ProcessName).Length > 1)
                {
                    return;
                }

                ServiceHost host = new ServiceHost(typeof(KryptonGridService.WCFServices));

                host.Open();
                foreach (ServiceEndpoint se in host.Description.Endpoints)
                {
                    Console.WriteLine("Address : {0}, Binding : {1}, Contract : {2}", se.Address, se.Binding, se.Contract.ContractType);
                }
                Console.WriteLine("               ");
                Console.WriteLine("               ");
                Console.WriteLine("               ");
                Console.WriteLine("Service Started");
                Console.ReadLine();

                host.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #24
0
        public static void Main()
        {
            Uri baseAddress = new Uri("http://localhost:8000/" + Guid.NewGuid().ToString());

            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);
            try
            {
                // ServiceDiscoveryBehavior is added through the configuration
                // UdpDiscoveryEndpoint is added through the configuration

                serviceHost.Open();

                Console.WriteLine("Calculator Service started {0}", baseAddress);
                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate the service");
                Console.WriteLine();
                Console.ReadLine();

                serviceHost.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }   

            if (serviceHost.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting the service...");
                serviceHost.Abort();
            }
        }
Пример #25
0
        static void Main(string[] args)
        {
            Console.Title = "BasicHttp Service Host";
            Console.Write("\n  Starting Programmatic Basic Service");
            Console.Write("\n =====================================\n");

            var repo = new DbRepository();

            //repo.ClearAll();

            System.ServiceModel.ServiceHost host = null;
            try
            {
                host = CreateChannel("http://localhost:8080/RemoteRepositoryService");                 // Must match URL specified in client
                host.Open();
                Console.Write("\n  Started RemoteRepositoryService - Press key to exit:\n");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.Write("\n\n  {0}\n\n", ex.Message);
                return;
            }
            host.Close();
        }
Пример #26
0
      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();
      }
Пример #27
0
        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;
            }
        }
Пример #28
0
        static void Main()
        {
            //HandleDb4o.LoadTestData(HandleDb4o.StoreYapFileName);
            Console.WriteLine("Starting...");
            var crossDomainserviceHost = new ServiceHost(typeof(CrossDomainService));
            crossDomainserviceHost.Open();
            
            var serviceHost = new ServiceHost(typeof(QuestionnaireService));
            serviceHost.Open();
            
            Console.WriteLine("Started.");

            Console.ReadLine();
            Console.WriteLine("Closing...");
            serviceHost.Close();
            crossDomainserviceHost.Close();
            Console.WriteLine("Closed.");

            var db = HandleDb4o.Database;
            if(db != null)
            {
                db.Close();
            }

        }
Пример #29
0
        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();
            }
        }
Пример #30
0
 protected override void OnStop()
 {
     if (serviceHost != null)
     {
         serviceHost.Close();
     }
 }
Пример #31
0
        static void Main(string[] args)
        {
            ServiceHost selfHost = new ServiceHost(typeof(Controller));

            try
            {
                // Add a service endpoint.
                selfHost.AddServiceEndpoint(typeof(IController), new NetTcpBinding(), Constants.URI);

                // 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();
            }
        }
Пример #32
0
        static void Main(string[] args)
        {
            Console.Title = "ClaimsEnumerationHost";
            using (ServiceHost serviceHost = new ServiceHost(typeof(ClaimsEnumeratorService.ClaimsEnumerator)))
            {
                try
                {

                    serviceHost.Open();

                    Console.WriteLine("The ClaimsEnumerations service is now running.");
                    Console.WriteLine("EndPoints: ");
                    foreach (ServiceEndpoint ep in serviceHost.Description.Endpoints)
                        Console.WriteLine(" " + ep.Address.Uri.ToString());
                    Console.WriteLine("Press <ENTER> to terminate Service.");
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    // The service can now be accessed.
                    Console.ReadLine();
                    serviceHost.Close();
                }
                catch (CommunicationException exc)
                {
                    serviceHost.Abort();
                    Console.WriteLine(exc.Message);
                    Console.ReadLine();
                }
            }
        }
Пример #33
0
        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();
            }
        }
 /// <summary>
 /// Stops the service
 /// </summary>
 public void Stop()
 {
     if (host != null)
     {
         //subscriptionService.UnsubscribeAllClients();
         host.Close();
         host = null;
     }
 }
 public void Stop()
 {
     if (serviceHost != null)
     {
         Logging.Log(LogLevelEnum.Info, "Stopping WCF service");
         serviceHost.Close();
         serviceHost = null;
         Logging.Log(LogLevelEnum.Info, "WCF service stopped");
     }
 }
Пример #36
0
        static void Main(string[] args)
        {
            var host = new System.ServiceModel.ServiceHost(typeof(MedicSchedulerService));

            //host.AddServiceEndpoint(typeof(IMedicSchedulerService), new BasicHttpBinding(), "");
            host.Open();
            Console.WriteLine("Service host start");
            Console.ReadLine();
            host.Close();
        }
Пример #37
0
        public ActionResult InvokeTCP()
        {
            System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(Assignment1_Section1.SayHello));
            host.Open();
            SayHelloProxy proxy = new SayHelloProxy();

            ViewBag.Message = proxy.DoWork("Hello World");
            host.Close();
            return(RedirectToAction("Home"));
        }
Пример #38
0
 static void Main()
 {
     using (var host = new System.ServiceModel.ServiceHost(typeof(ServiceApp.MSSQLService)))//выделение памяти при запуске
     {
         host.Open();
         Console.WriteLine("Service started....\nInput something to close.");
         Console.ReadKey();
         host.Close();
     }
 }
Пример #39
0
        public ActionResult InvokeHTTP()
        {
            Uri httpURI = new Uri("http://localhost:55431/");

            System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(Assignment1_Section1.SayHello), httpURI);
            host.Open();
            SayHelloProxy proxy = new SayHelloProxy();

            ViewBag.Message = proxy.DoWork("Hello World");
            host.Close();
            return(RedirectToAction("Home"));
        }
Пример #40
0
 public override void Stop()
 {
     lock (syncLock)
     {
         if (serviceHost.State != CommunicationState.Closed)
         {
             serviceHost.Close();
             serviceHost = null;
         }
         waitHandle.Set();
     }
 }
Пример #41
0
        /// <summary>
        /// Stops the AutoRental tcp services
        /// </summary>
        /// <param name="host"></param>
        /// <param name="serviceDescription"></param>
        static void StopService(SM.ServiceHost host, string serviceDescription)
        {
            if (host == null)
            {
                return;
            }

            if (host.State != SM.CommunicationState.Closed)
            {
                host.Close();
                Console.WriteLine("\nService {0} stopped.", serviceDescription);
            }
        }
Пример #42
0
        protected override void OnStop()
        {
            _log.Error("服务停止");


            if (_hostCardRecognize.State == CommunicationState.Opened)
            {
                _hostCardRecognize.Close();
            }
            if (_hostBroadcast.State == CommunicationState.Opened)
            {
                _hostBroadcast.Close();
            }
        }
Пример #43
0
        static void Main(string[] args)
        {
            //Uri baseAddress = new Uri("http://localhost:8081/User");

            Binding wsBinding = new WSHttpBinding();

            System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(UserProvider));
            host.AddServiceEndpoint(typeof(IUserProvider), wsBinding,
                                    "http://localhost:8081/User");
            host.Open();
            Console.WriteLine("Service Open");
            Console.ReadLine();
            host.Close();
        }
Пример #44
0
        public void Stop()
        {
            _serviceCore = null;
            if (_serviceHost == null)
            {
                return;
            }

            if (_serviceHost.State == CommunicationState.Opened)
            {
                _serviceHost.Close();
            }

            _serviceHost = null;
        }
Пример #45
0
        public static void Main(string[] args)
        {
            // WCF hosting for Ticker
            SH Host = new SH(typeof(TickerService.TickerImplementation));

            Host.Open();

            Console.WriteLine(String.Format("Service started at {0}", DateTime.Now.ToString()));
            Console.WriteLine("[Press ENTER key to quit -or- F5 to clone the clients]");

            // Start WPF app
            App.Main();

            Console.ReadKey();
            Host.Close();
        }
Пример #46
0
 static void Main(string[] args)
 {
     System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(ClienteService));
     host.AddServiceEndpoint(typeof(IClienteService), new BasicHttpBinding(), new Uri("http://localhost:8080/clientes"));
     try
     {
         host.Open();
         Console.ReadLine();
         host.Close();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         host.Abort();
         Console.ReadLine();
     }
 }
Пример #47
0
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:9001/TheService");

            using (System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(TheService), baseAddress))
            {
                host.AddServiceEndpoint(typeof(ITheService), new WSHttpBinding(), "");
                ServiceMetadataBehavior serviceBehavior = new ServiceMetadataBehavior();
                serviceBehavior.HttpGetEnabled = true;
                host.Description.Behaviors.Add(serviceBehavior);

                host.Open();

                Console.WriteLine("Hit enter to exit ...");
                Console.Read();

                host.Close();
            }
        }
Пример #48
0
        public static void Main(string[] args)
        {
            var httpBaseAddress = new Uri("http://localhost:13666/MessageService");

            using (var messageQueueHost = new System.ServiceModel.ServiceHost(typeof(MessageQueue), httpBaseAddress))
            {
                messageQueueHost.AddServiceEndpoint(typeof(IMessageQueue), new WSHttpBinding(), "");

                var serviceBehavior = new ServiceMetadataBehavior
                {
                    HttpGetEnabled = true
                };
                messageQueueHost.Description.Behaviors.Add(serviceBehavior);

                messageQueueHost.Open();
                Console.WriteLine($"Service is live now at: {httpBaseAddress}\n\n");
                Console.ReadKey();
                messageQueueHost.Close();
            }
        }
Пример #49
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            if (host1.State != CommunicationState.Closed)
            {
                host1.Close();
            }
            if (host2.State != CommunicationState.Closed)

            {
                host2.Close();
            }

            if (host3.State != CommunicationState.Closed)

            {
                host3.Close();
            }

            this.label1.Text = "服务停止成功!";
        }
 /********************
  *    Destroy!!!!
  *********************/
 public void destroy()
 {
     try
     {
         //példány konstruktor
         //logoljuk, mert kíváncsiak vagyunk, hogy csak egyszer hívódik e meg.
         log.Info("LogXServer.destroy() begin..");
         xafServiceHost.Close();
         log.Info("XAF service closed.");
         wsHostPrivate.Close();
         log.Info("WS Private service stopped.");
         wsHostPublic.Close();
         log.Info("WS Public service stopped.");
         opcClient.destroy();
         serverApplication.Dispose();
         log.Info("LogXServer.destroy() end.");
     }
     catch (Exception e)
     {
         log.Fatal("Error in LogXServer.destroy()", e);
     }
 }
Пример #51
0
 /********************
  *    Destroy!!!!
  *********************/
 public void destroy()
 {
     try
     {
         //példány konstruktor
         //logoljuk, mert kíváncsiak vagyunk, hogy csak egyszer hívódik e meg.
         Console.WriteLine("LogXServer.destroy() begin..");
         xafServiceHost.Close();
         System.Console.WriteLine("XAF service closed.");
         wsHostPrivate.Close();
         Console.WriteLine("WS Private service stopped.");
         wsHostPublic.Close();
         Console.WriteLine("WS Public service stopped.");
         opcClient.destroy();
         Console.WriteLine("LogXServer.destroy() end.");
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception occurs: " + e.Message);
         Console.WriteLine("Press Enter to close.");
         Console.ReadLine();
     }
 }
Пример #52
0
        static void Main(string[] args)
        {
            // read settings
            var appSettings = ConfigurationManager.AppSettings;

            string baseAddressString = appSettings["baseAddress"];

            Uri baseAddress = baseAddressString == null ?
                              new Uri("http://localhost:80/Temporary_Listen_Addresses/CashDiscipline") :
                              new Uri(baseAddressString);

            using (System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(Service1), baseAddress))
            {
                // Enable metadata publishing.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);

                // enable debugging
                ServiceBehaviorAttribute sba = (ServiceBehaviorAttribute)host.Description.Behaviors[typeof(ServiceBehaviorAttribute)];
                sba.IncludeExceptionDetailInFaults = true;

                // Open the ServiceHost to start listening for messages. Since
                // no endpoints are explicitly configured, the runtime will create
                // one endpoint per base address for each service contract implemented
                // by the service.
                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                // Close the ServiceHost.
                host.Close();
            }
        }
Пример #53
0
        /// <summary>
        /// Main
        /// Main entry for program
        /// </summary>
        /// <param name="args">none used</param>
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Starting Hello Authenticate Demo Service...");
                // Note: Do not put this service host constructor within a using clause.
                // Errors in Open will be trumped by errors from Close (implicitly called from ServiceHost.Dispose).
                System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(HelloAuthenticateService));
                host.Open();

                Console.WriteLine("The Hello Authenticate Demo Service has started.");
                Console.WriteLine("Press <ENTER> to quit.");
                Console.ReadLine();
                host.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "." + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name);
                Console.WriteLine("An error occurred: " + ex.Message);
                Console.WriteLine("Press <ENTER> to quit.");
                Console.ReadLine();
            }

        } // end of main method
Пример #54
0
 static void StopService(SM.ServiceHost host, string serviceDescription)
 {
     host.Close();
     Console.WriteLine("Service '{0}' stopped.", serviceDescription);
 }
Пример #55
0
 static void StopService(SM.ServiceHost host, string serviceDescription)
 {
     host.Close();        Console.WriteLine($"Service {serviceDescription} stopped.");
 }
Пример #56
0
 private static void CloseHost()
 {
     _host?.Close();
 }
Пример #57
0
 static void StopService(SM.ServiceHost host, string description)
 {
     host.Close();
     Console.WriteLine(string.Format("Service {0} is stopped", description));
 }
Пример #58
0
 private void StopService(SM.ServiceHost host, string serviceDescription)
 {
     host.Close();
     Log.Info("Service '{0}' stopped.", serviceDescription);
 }
Пример #59
0
 private static void StopService(SM.ServiceHost host, string serviceDescription)
 {
     host.Close();
     System.Console.WriteLine("Service {0} stopped.", serviceDescription);
 }
 static void StopService(SM.ServiceHost host, string description)
 {
     host.Close();
     Console.WriteLine("Service {0} stopped.", description);
 }