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


C# HttpSelfHostServer.Dispose方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            var port = ConfigurationManager.AppSettings["Port"] ?? "8080";
            var hostname = ConfigurationManager.AppSettings["Hostname"] ?? "localhost";

            //The url that the service can be called on
            var serviceUrl = string.Format("http://{0}:{1}", hostname, port);

            //Service configuration
            var config = new HttpSelfHostConfiguration(serviceUrl);

            //Add routes to controllers
            config.Routes.MapHttpRoute("DefaultApi ", "api/{controller}/{id}", new { id = RouteParameter.Optional });

            //Writes list of available mediatype formatters to console
            Console.WriteLine("{0}{1}", "Registered media type formatters:\n", string.Join("\n", config.Formatters.Select(x => x.GetType())));

            //Initialize server
            _selfHostServerServer = new HttpSelfHostServer(config);

            //Start server
            _selfHostServerServer.OpenAsync().Wait();
            Console.WriteLine("{1}Self hosting server is running on: {0}", serviceUrl, Environment.NewLine);
            Console.WriteLine("Press Enter to quit.");
            Console.ReadLine();

            //Wires up application close handler
            AppDomain.CurrentDomain.ProcessExit += (s, e) =>
                                                       {
                                                           //Close server
                                                           _selfHostServerServer.CloseAsync();
                                                           _selfHostServerServer.Dispose();
                                                       };
        }
开发者ID:paulinfrancis,项目名称:WebApiDemo,代码行数:34,代码来源:Program.cs

示例2: Main

        static void Main()
        {
            var form = new RenderForm("KinectLight");
            form.Size = new System.Drawing.Size(1920,1200);

            var desc = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed = true,
                OutputHandle = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };

            SharpDX.Direct3D10.Device1 device;
            SwapChain swapChain;
            SharpDX.Direct3D10.Device1.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, SharpDX.Direct3D10.FeatureLevel.Level_10_1, out device, out swapChain);

            var d2dFactory = new SharpDX.Direct2D1.Factory();
            var surface = Surface.FromSwapChain(swapChain, 0);

            RenderTarget dc = new RenderTarget(d2dFactory, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));

            MainGame.Instance.Height = form.ClientSize.Height;
            MainGame.Instance.Width = form.ClientSize.Width;
            GameTime gameTime = new GameTime();

            var config = new HttpSelfHostConfiguration("http://localhost:8080");

            config.Routes.MapHttpRoute(
                "API Default", "api/{controller}/{action}/{name}",
                new { id = RouteParameter.Optional });

            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();

            RenderLoop.Run(form, () =>
            {
                gameTime.StartFrame();
                MainGame.Instance.Update(gameTime);
                dc.BeginDraw();
                dc.Clear(Colors.White);
                MainGame.Instance.Render(dc);
                var res = dc.EndDraw();
                swapChain.Present(1, PresentFlags.None);
                //Thread.Sleep(1);
            });

            server.Dispose();
            MainGame.Instance.Dispose();
            dc.Dispose();
            surface.Dispose();
            d2dFactory.Dispose();
            device.Dispose();
            swapChain.Dispose();
        }
开发者ID:aL3891,项目名称:KinectLight,代码行数:58,代码来源:Program.cs

示例3: Run

        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("AzureTicker.Worker entry point called", "Information");

            HttpSelfHostServer server = null;
            try
            {
                var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["webapi"];
                Uri baseAddress = new Uri(string.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint.ToString()));

                // Set up server configuration
                HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress);
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );

                // Create server
                server = new HttpSelfHostServer(config);

                // Start listening
                server.OpenAsync().Wait();
            }
            catch (Exception e)
            {
                Trace.WriteLine("Failed to open Web Api host.", "Error");
                Trace.WriteLine(e.ToString(), "Error");
                if (server != null)
                {
                    server.Dispose();
                }
            }

            while (true)
            {
                Thread.Sleep(10000);
            }
        }
开发者ID:AppliedIS,项目名称:AzureTicker,代码行数:40,代码来源:WorkerRole.cs

示例4: ValueController_WithGetMethos_ShouldReturnValidData_NoBaseClass

        public void ValueController_WithGetMethos_ShouldReturnValidData_NoBaseClass()
        {
            HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration("http://localhost:8080");
            configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
            configuration.Services.Replace(typeof(IAssembliesResolver), new WebApiClassBase.TestAssemblyResolver(typeof(ValuesController)));
            configuration.Routes.MapHttpRoute("Default", "{controller}", new { controller = "Home" });

            HttpSelfHostServer server = new HttpSelfHostServer(configuration);
            try
            {
                server.OpenAsync().Wait();

                var request = new HttpRequestMessage();

                request.RequestUri = new Uri("http://localhost:8080");

                request.Method = HttpMethod.Get;

                var client = new HttpClient(server);
                using (HttpResponseMessage response = client.SendAsync(request).Result)
                {
                    response.Should().Not.Be.Null();
                    response.IsSuccessStatusCode.Should().Be.True();

                    string[] result = response.Content.ReadAsAsync<string[]>().Result;

                    result.Length.Should().Be.EqualTo(4);
                    result[0].Should().Be.EqualTo("http://tostring.it");
                    result[1].Should().Be.EqualTo("http://imperugo.tostring.it");
                    result[2].Should().Be.EqualTo("http://twitter.com/imperugo");
                    result[3].Should().Be.EqualTo("http://www.linkedin.com/in/imperugo");
                }
            }
            finally
            {
                configuration.Dispose();
                server.Dispose();
            }
        }
开发者ID:bmontemer,项目名称:Spike,代码行数:39,代码来源:ValuesControllerWithoutBaseClass.cs

示例5: RunControlEndpoint

        static async Task RunControlEndpoint(IPEndPoint controlEP, MessagingFactory messagingFactory)
        {
            var config = new HttpSelfHostConfiguration(new UriBuilder(Uri.UriSchemeHttp, "localhost", controlEP.Port).Uri);

            var injector = new StandardKernel();
            injector.Bind<MessagingFactory>().ToConstant(messagingFactory);
            config.DependencyResolver = new Ninject.WebApi.DependencyResolver.NinjectDependencyResolver(injector);

            config.Routes.MapHttpRoute("API", "{controller}/{id}", new { id = RouteParameter.Optional });
            var controlServer = new HttpSelfHostServer(config);
            try
            {
                await controlServer.OpenAsync();
                Trace.TraceInformation("Control endpoint listening at {0}", config.BaseAddress);
            }
            catch (Exception exception)
            {
                controlServer.Dispose();
                Trace.TraceError("Control endpoint cannot open, {0}", exception.Message);
                throw;
            }
            await ClosingEvent.Task;
            try
            {
                await controlServer.CloseAsync();
            }
            finally
            {
                controlServer.Dispose();
            }
        }
开发者ID:uhansen,项目名称:D2C-Ep4-LedBlinker,代码行数:31,代码来源:SwitchServer.cs


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