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


C# ServiceHost.Open方法代码示例

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


在下文中一共展示了ServiceHost.Open方法的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: Open_Open_error

 public void Open_Open_error()
 {
     var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name;
     var serv = new Service(null);
     using (var host = new ServiceHost(serv, new Uri[] { new Uri(address) }))
     {
         var b = new NetNamedPipeBinding();
         host.AddServiceEndpoint(typeof(IService), b, address);
         host.Open();
         host.Open();
     }
 }
开发者ID:OpenSharp,项目名称:NDceRpc,代码行数:12,代码来源:HostTests.cs

示例3: OpenServiceHost

 private void OpenServiceHost()
 {
     cacheServiceHost = new ServiceHost(new InvalidateCacheService(CacheInvalidated, () => cacheServiceHost.Close()), invalidateCacheUri);
     cacheServiceHost.AddServiceEndpoint(typeof(IInvalidateCacheService), new NetNamedPipeBinding(), invalidateCacheUri);
     try
     {
         cacheServiceHost.Open();
     }
     catch (Exception ex)
     {
         cacheServiceHost.Close();
         cacheServiceHost.Open();
     }
 }
开发者ID:burkhartt,项目名称:Bennington,代码行数:14,代码来源:InvalidateCacheEndpoint.cs

示例4: Main

		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
		}
开发者ID:Helen1987,项目名称:edu,代码行数:32,代码来源:Program.cs

示例5: Main

        // Host the service within this EXE console application.
        public static void Main()
        {
            WSHttpBinding binding = new WSHttpBinding();
            binding.Name = "binding1";
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.Security.Mode = SecurityMode.Message;
            binding.ReliableSession.Enabled = false;
            binding.TransactionFlow = false;
            
            Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");

            // Create a ServiceHost for the CalculatorService type and provide the base address.
            using(ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
            {
                serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, baseAddress);
                // Open the ServiceHostBase 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();
                             
            }
                    
        }
开发者ID:ssickles,项目名称:archive,代码行数:28,代码来源:service.cs

示例6: Main

        private static void Main()
        {
            var serviceAddress = new Uri("http://localhost:8881/strings");
            ServiceHost selfHost = new ServiceHost(
                typeof(StringsService),
                serviceAddress);

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

            selfHost.Open();
            Console.WriteLine("Running at " + serviceAddress);

            StringsServiceClient client = new StringsServiceClient();

            using (client)
            {
                var result = client.StringContainsOtherString("as", "asblablass"); // returns 2
                Console.WriteLine("Using the service: \"as\" is contained in \"asblablass\" {0} times\n", result);
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:25,代码来源:Start.cs

示例7: 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

示例8: Main

        public static void Main(string[] args)
        {
            if (System.Environment.UserInteractive)
            {
                string parameter = string.Concat(args);

                try
                {
                    ServiceHost serviceHost = new ServiceHost(typeof(InfoProviderService));

                    serviceHost.Open();
                    LogManager.Instance.WriteInfo("InfoProvider Server Starting...........");

                }
                catch (Exception ex)
                {
                    LogManager.Instance.WriteError(ex.Message);
                }
            }
            else
            {

                ServiceBase.Run(new Program());

            }

        }
开发者ID:ddotan,项目名称:InfoProvider.ASPMVC.WCF,代码行数:27,代码来源:Program.cs

示例9: Main

 static void Main(string[] args)
 {
     ServiceHost hostA = null;
     ServiceHost hostB = null;
     try
     {
         hostA = new ServiceHost(typeof(BusinessServices.ServiceA));
         hostB = new ServiceHost(typeof(BusinessServices.ServiceB));
         hostA.Open();
         hostB.Open();
         ServiceEndpointCollection listA = hostA.Description.Endpoints;
         foreach (ServiceEndpoint item in listA)
         {
             Console.WriteLine(item.Address);
         }
         Console.WriteLine();
         listA = hostB.Description.Endpoints;
         foreach (ServiceEndpoint item in listA)
         {
             Console.WriteLine(item.Address);
         }
         Console.WriteLine();
         Console.WriteLine("Press <ENTER> to terminate Host");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         CloseHost(hostA);
         CloseHost(hostB);
     }
     Console.ReadLine();
     CloseHost(hostA);
     CloseHost(hostB);
 }
开发者ID:ChuckTest,项目名称:WCFTest,代码行数:34,代码来源:Program.cs

示例10: Main

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

                if (host.State == CommunicationState.Opened)
                {
                    Console.WriteLine("The service is available:");
                    foreach (var address in host.BaseAddresses)
                    {
                        Console.WriteLine(address);
                    }
                    Console.WriteLine();
                }
                else
                {
                    throw new System.Exception("The service is not in a state OPENED.");
                }
            }
            catch (System.Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey(true);
        }
开发者ID:ZyshchykMaksim,项目名称:WCF.REST,代码行数:28,代码来源:Program.cs

示例11: StartServiceHost

 static void StartServiceHost()
 {
     _svcHost = new ServiceHost(_worldSvr);
     _svcHost.Faulted += new EventHandler(svcHost_Faulted);
     _svcHost.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(svcHost_UnknownMessageReceived);
     _svcHost.Open();
 }
开发者ID:natedahl32,项目名称:EqEmulator-net,代码行数:7,代码来源:Program.cs

示例12: Start

        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);

        }
开发者ID:nishanperera,项目名称:NServiceBus.MessageRouting,代码行数:30,代码来源:Listener.cs

示例13: 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

示例14: Main

        static void Main()
        {
            //run the program and visit this URI to confirm the service is working
            Uri baseAddress = new Uri("http://localhost:8000/GPSSim");
            ServiceHost host = new ServiceHost(typeof(GPSSim), baseAddress);

            //basicHttpBinding is used because WS binding is currently unsupported
            host.AddServiceEndpoint(typeof(IGPSSim), new BasicHttpBinding(),   "GPS Sim Service");

            try
            {
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                host.Description.Behaviors.Add(smb);
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("An exception occurred: {0}", e.Message);
                host.Abort();
            }

            host.Open();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
开发者ID:keyboardP,项目名称:GPSSim,代码行数:27,代码来源:Program.cs

示例15: StartServer

 protected override IDisposable StartServer(int responseSize)
 {
     ServiceHost host = new ServiceHost(CreateService(responseSize), UriBase);
     host.AddServiceEndpoint(typeof(IWcfSampleService), GetBinding(BindingName), BindingName);
     host.Open();
     return host;
 }
开发者ID:TijW,项目名称:protobuf-csharp-rpc,代码行数:7,代码来源:WcfBase.cs


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