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


C# HttpSelfHostConfiguration.EnsureInitialized方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {

            var baseAddress = "http://localhost:8080";
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress);
           // config.MessageHandlers.Add(new ProgressMessageHandler() { });


            // Web API 路由
            config.MapHttpAttributeRoutes();

            //全局允许CROS
            // config.EnableCors();//启用跨域


            config.Routes.MapHttpRoute
           (
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
            );
            config.MaxConcurrentRequests = 1000;
            var handlers = new DelegatingHandler[] { new PassiveAuthenticationMessageHandler(), new HttpServer() };
            var routeHandlers = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), handlers);
            config.Routes.MapHttpRoute(
                   name: "CustomerRouter",
                  routeTemplate: "MyAPI/{Controller}/{Action}/Id",
                  defaults: new { Id = RouteParameter.Optional },
                  constraints: null,
                  handler: routeHandlers
                );
            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync();


            TaskManager.Instance.Initialize();
            TaskManager.Instance.Start();
           DefaultHttpBatchHandler batchHandler = new DefaultHttpBatchHandler(server);

            Console.WriteLine("Server  http://localhost:8080   Open now ....at {0}..", server.Configuration.VirtualPathRoot);
            config.EnsureInitialized();
            foreach (var route in config.Routes)
            {
                System.Diagnostics.Debug.WriteLine(route);
            }

            Console.ReadLine();

        }
开发者ID:wjkhappy14,项目名称:aspnetwebstack,代码行数:49,代码来源:Program.cs

示例2: OnStart

        protected override void OnStart(string[] args)
        {
            Uri baseAddress = new Uri("http://" + ConfigurationManager.AppSettings["server"] + GetPort());
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress)
            {
                HostNameComparisonMode = HostNameComparisonMode.Exact
            };

            string origins = ConfigurationManager.AppSettings["corsItems"];
            if (string.IsNullOrEmpty(origins))
            {
                origins = "*";
            }
            config.EnableCors(new EnableCorsAttribute(origins, "*", "*"));

            var formatters = GlobalConfiguration.Configuration.Formatters;
            formatters.Remove(formatters.XmlFormatter);

            WebApiConfig.Register(config);
            config.MapHttpAttributeRoutes();
            config.EnsureInitialized();

            _server = new HttpSelfHostServer(config);
            // Start listening
            _server.OpenAsync().Wait();
            System.Console.WriteLine("Listening on " + baseAddress);
        }
开发者ID:blueghostuk,项目名称:trainnotifier-server,代码行数:27,代码来源:Service.cs


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