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


C# HttpSelfHostConfiguration.MapHttpAttributeRoutes方法代码示例

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


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

示例1: Main

        public static void Main(string[] args)
        {
            var config = new HttpSelfHostConfiguration("http://127.0.0.1:3001");

            config.MapHttpAttributeRoutes();
            config.EnableCors();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "ReportsApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            using (HttpSelfHostServer server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }
        }
开发者ID:grimcoder,项目名称:ProduceMarketRESTWebAPI,代码行数:27,代码来源:Program.cs

示例2: PrinterService

        public PrinterService()
        {
            InitializeComponent();

            config = new HttpSelfHostConfiguration(AppConfig.BaseUrl);
            config.MapHttpAttributeRoutes();
        }
开发者ID:AliakseiDudko,项目名称:PrinterWebService,代码行数:7,代码来源:PrinterService.cs

示例3: Main

        /// <summary>
        /// The program main method
        /// </summary>
        /// <param name="args">The program arguments</param>
        private static void Main(string[] args)
        {
            var config = new HttpSelfHostConfiguration(ServiceAddress);

            config.MapHttpAttributeRoutes();
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
            config.EnableCors(new EnableCorsAttribute("*", "*", "*"));

            using (var server = new HttpSelfHostServer(config)) {
                try {
                    server.OpenAsync().Wait();
                    Console.WriteLine("Service running on " + ServiceAddress + ". Press enter to quit.");
                    Console.ReadLine();
                }
                catch (Exception e) {
                    if (!IsAdministrator()) {
                        Console.WriteLine("Please restart as admin.");
                        Debug.WriteLine("Restart Visual Studio as admin");
                    }
                    else {
                        Console.WriteLine("Server failed to start.");
                    }
                    Console.ReadLine();
                }
            }
        }
开发者ID:CryptidID,项目名称:Cryptid,代码行数:30,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            var address = "http://localhost:900";
            var config = new HttpSelfHostConfiguration(address);
            config.MapHttpAttributeRoutes();

            using (var server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                Console.WriteLine("Server running at {0}. Press any key to exit", address);

                var client = new HttpClient() {BaseAddress = new Uri(address)};

                var persons = client.GetAsync("person").Result;
                Console.WriteLine(persons.Content.ReadAsStringAsync().Result);

                var newPerson = new Person {Id = 3, Name = "Luiz"};
                var response = client.PostAsJsonAsync("person", newPerson).Result;

                if (response.IsSuccessStatusCode)
                {
                    var person3 = client.GetAsync("person/3").Result;
                    Console.WriteLine(person3.Content.ReadAsStringAsync().Result);
                }

                Console.ReadLine();
            }

        }
开发者ID:amanarorasti,项目名称:dotnet,代码行数:29,代码来源:Program.cs

示例5: Main

 static void Main(string[] args)
 {
     HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration("http://localhost:3721");
     configuration.MapHttpAttributeRoutes();
     HttpSelfHostServer server = new HttpSelfHostServer(configuration);
     server.OpenAsync().Wait();
     Console.Read();
 }
开发者ID:chenboyi081,项目名称:asp-net-web-api-2-samples,代码行数:8,代码来源:Program.cs

示例6: Main

        private static void Main()
        {
            const string address = "http://localhost:925/";

            var config = new HttpSelfHostConfiguration(address);
            config.MapHttpAttributeRoutes();
            var handler = new HawkMessageHandler(
                async id => new HawkCredential
                {
                    Id = id,
                    Key = "abcdefghijkl",
                    Algorithm = "sha256",
                    User = "filip"
                }, 4, true);

            config.MessageHandlers.Add(handler);

            using (var server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                var client = new HttpClient();

                //this will fail
                var request = new HttpRequestMessage(HttpMethod.Get, address + "test");
                var response = client.SendAsync(request).Result;
                Console.WriteLine(response.StatusCode);
                Console.WriteLine();

                var credential = new HawkCredential
                {
                    Id = "this-is-my-id",
                    Key = "abcdefghijkl",
                    Algorithm = "sha256",
                    User = "filip"
                };

                var clientHandler = new HawkClientMessageHandler(new HttpClientHandler(), credential, ts: DateTime.Now);
                var client2 = new HttpClient(clientHandler);

                //this will succeed
                request = new HttpRequestMessage(HttpMethod.Get, address + "test");
                var response2 = client2.SendAsync(request).Result;
                Console.WriteLine(response2.StatusCode);
                Console.WriteLine(response2.Content.ReadAsStringAsync().Result);
                Console.WriteLine();

                Console.WriteLine("Sleeping to get outside of the timestamp window. Next request will fail - replay protection.");
                Thread.Sleep(5000);

                //this will fail
                request = new HttpRequestMessage(HttpMethod.Get, address + "test");
                var response3 = client2.SendAsync(request).Result;
                Console.WriteLine(response3.StatusCode);
                Console.WriteLine();

                Console.ReadLine();
            }
        }
开发者ID:diouf,项目名称:apress-recipes-webapi,代码行数:58,代码来源:Program.cs

示例7: MediaStreamingServer

        public MediaStreamingServer(int port = 8080)
        {
            Address = "http://" + Ext.GetIp4Address() + ":" + port;
            var config = new HttpSelfHostConfiguration(Address);
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new {id = RouteParameter.Optional}
                );
            config.TransferMode = TransferMode.Streamed;
            httpSelfHostServer = new HttpSelfHostServer(config);
        }
开发者ID:Rotvig,项目名称:AirPlayer,代码行数:11,代码来源:MediaStreamingServer.cs

示例8: OnStart

 protected override void OnStart(string[] args)
 {
     var selfHostConfiguraiton = new HttpSelfHostConfiguration("http://localhost:9999/");
     selfHostConfiguraiton.Routes.MapHttpRoute(
         name: "ApiRoute",
         routeTemplate: "api/{controller}",
         defaults: null
     );
     selfHostConfiguraiton.MapHttpAttributeRoutes();
     selfHostConfiguraiton.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
     _webApiServer = new HttpSelfHostServer(selfHostConfiguraiton);
     _webApiServer.OpenAsync().Wait();
 }
开发者ID:sts11vcd71,项目名称:NetworkTools,代码行数:13,代码来源:WatchdogService.cs

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

示例10: Service

        public Service()
        {
            var selfHostConfiguraiton = new HttpSelfHostConfiguration("http://localhost:5555");

            selfHostConfiguraiton.MapHttpAttributeRoutes();

            selfHostConfiguraiton.MapODataServiceRoute("api", "api", GetApiModel());

            selfHostConfiguraiton.Routes.MapHttpRoute(
                name: "DefaultApiRoute",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            server = new HttpSelfHostServer(selfHostConfiguraiton);
        }
开发者ID:sultanchik,项目名称:TestOdataRouting,代码行数:16,代码来源:Service.cs

示例11: SetUp

        void SetUp()
        {
            Injector.Resolver = new TestResolver();
            var endpoint = "http://localhost:40000";

            target = new RemoteDecisionService(endpoint);
            var config = new HttpSelfHostConfiguration(endpoint);

            config.DependencyResolver = new InjectorDependencyResolver();

            // Decision routes
            config.MapHttpAttributeRoutes();

            server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();
        }
开发者ID:TruffleMuffin,项目名称:Decisions,代码行数:16,代码来源:RemoteDecisionsServiceTests.cs

示例12: Start

        public Uri Start(string serviceName, string version)
        {
            var uri = Configuration.GetUri();
            var config = new HttpSelfHostConfiguration(uri);

            // Attribute routing.
            config.MapHttpAttributeRoutes();

            // Convention-based routing.
            config.Routes.MapHttpRoute(
                "API Default", "{controller}/{id}",
                new { id = RouteParameter.Optional });

            var server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();
            return uri;
        }
开发者ID:rogeralsing,项目名称:Microphone,代码行数:17,代码来源:WebApiProvider.cs

示例13: Start

        public void Start()
        {
            var nodeConfigString = File.ReadAllText("config.json");
            var settings = new Newtonsoft.Json.JsonSerializerSettings
            {
                TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto,
            };
            var config = Newtonsoft.Json.JsonConvert.DeserializeObject<JSONConfig>(nodeConfigString, settings);

            // config Syslog listener
            if (config.syslog.listenerEnabled)
            {
                var listener = new SyslogListener();
                Action<int> startListener = listener.Start;
                startListener.BeginInvoke(config.syslog.listenerPort, null, null);
            }

            // config PollEngine
            foreach (var node in (config.nodes ?? new JSONConfigNode[0]))
            {
                var pollNode = Activator.CreateInstance(typeof(PollingEngine).Assembly.GetType(node.type), new object[] { node.name, node.groups ?? new string[0], node.settings }) as PollNode;
                PollingEngine.TryAdd(pollNode);
            }
            PollingEngine.StartPolling();

            // config HTTP API
            var hostConfig = new HttpSelfHostConfiguration("http://127.0.0.1:" + config.http.listenerPort);
            // Remove the XML formatter
            hostConfig.Formatters.Remove(hostConfig.Formatters.XmlFormatter);
            hostConfig.Formatters.Add(new RazorFormatter());
            hostConfig.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto;
            hostConfig.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
            hostConfig.Formatters.JsonFormatter.SerializerSettings.Error += (x, y) =>
            {
                return;
            };
            hostConfig.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("type", "json", new MediaTypeHeaderValue("application/json")));
            // Attribute routing.
            hostConfig.MapHttpAttributeRoutes();
            hostConfig.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
            hostConfig.Filters.Add(new ApiExceptionFilterAttribute());

            httpServer = new HttpSelfHostServer(hostConfig);
            httpServer.OpenAsync().Wait();
        }
开发者ID:jdaigle,项目名称:nsysmon,代码行数:45,代码来源:ServiceHost.cs

示例14: Main

        static void Main(string[] args)
        {
            var config = new HttpSelfHostConfiguration("http://localhost:999");
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                  name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            var server = new HttpSelfHostServer(config);

            config.CacheOutputConfiguration().RegisterCacheOutputProvider(() => new MemoryCacheDefault());

            server.OpenAsync().Wait();

            Console.ReadKey();

            server.CloseAsync().Wait();
        }
开发者ID:hermsdorff,项目名称:AspNetWebApi-OutputCache,代码行数:19,代码来源:Program.cs

示例15: Service

        public Service()
        {
            var selfHostConfiguraiton = new HttpSelfHostConfiguration("http://localhost:5555");

            selfHostConfiguraiton.MapHttpAttributeRoutes();

            selfHostConfiguraiton.Routes.MapHttpRoute(
                name: "DefaultApiRoute",
                routeTemplate: "api/{controller}",
                defaults: null
                );

            selfHostConfiguraiton.Routes.MapHttpRoute(
                name: "ApiRouteWithAction",
                routeTemplate: "api/{controller}/{action}",
                defaults: null
                );

            server = new HttpSelfHostServer(selfHostConfiguraiton);
        }
开发者ID:sultanchik,项目名称:testWebApiSelfHost,代码行数:20,代码来源:Service.cs


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