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


C# HttpSelfHostConfiguration.MapODataServiceRoute方法代码示例

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


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

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

示例2: StartHttp

        private async Task StartHttp()
        {
            var baseAddress = new Uri($"http://localhost:{PortSetting}/");
            try
            {
                // Set up server configuration
                var config = new HttpSelfHostConfiguration(baseAddress);
                // config.Services.Replace(typeof(ITraceWriter), new SimpleTracer());

                //Add our way too simple Authentication 
                config.Filters.Add(new ZvsAuthenticatioFilter(this));

                // Web API routes
                config.MapHttpAttributeRoutes();

                var resolver = new WebApi2PluginDependencyResolver(this);
                config.DependencyResolver = resolver;

                config.EnableCors(new EnableCorsAttribute("*", "*", "*"));

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

                var builder = new ODataConventionModelBuilder();
                
                var scheduledTaskType = builder.EntityType<ScheduledTask>();
                scheduledTaskType.Ignore(t => t.StartTime);
                scheduledTaskType.Property(t => t.StartTimeOffset).Name = "StartTime";

                var deviceValueHistoryTaskType = builder.EntityType<DeviceValueHistory>();
                deviceValueHistoryTaskType.Ignore(t => t.DateTime);
                deviceValueHistoryTaskType.Property(t => t.DateTimeOffset).Name = "DateTime";
                
                var logEntryType = builder.EntityType<LogEntry>();
                logEntryType.Ignore(t => t.Datetime);
                logEntryType.Property(t => t.DateTimeOffset).Name = "Datetime";

                builder.EntitySet<Command>("Commands");
                var cExecute = builder.EntityType<Command>().Action("Execute");
                cExecute.Parameter<string>("Argument");
                cExecute.Parameter<string>("Argument2");


                builder.EntitySet<BuiltinCommand>("BuiltinCommands");
                builder.EntitySet<Device>("Devices");
                builder.EntitySet<DeviceCommand>("DeviceCommands");
                builder.EntitySet<DeviceTypeCommand>("DeviceTypeCommands");
                builder.EntitySet<DeviceValueTrigger>("DeviceValueTriggers");
                builder.EntitySet<DeviceValue>("DeviceValues");
                builder.EntitySet<DeviceValueHistory>("DeviceValueHistories");
                builder.EntitySet<Group>("Groups");
                builder.EntitySet<Scene>("Scenes");
                builder.EntitySet<SceneStoredCommand>("SceneStoredCommands");
                builder.EntitySet<ScheduledTask>("ScheduledTasks");
                builder.EntitySet<LogEntry>("LogEntries");
                builder.Namespace = "Actions";
                config.MapODataServiceRoute("ODataRoute", "odata4", builder.GetEdmModel());

                //config.MapODataServiceRoute(
                //routeName: "ODataRoute",
                //routePrefix: null,
                //model: builder.GetEdmModel());

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

                // Start listening
                await HttpSelfHostServer.OpenAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not start server: {0}", e.GetBaseException().Message);
            }

            await Log.ReportInfoFormatAsync(CancellationToken, "WebApi2 Server Online on port {0} {1} SSL", baseAddress, UseSslSetting ? "using" : "not using");
        }
开发者ID:ruisebastiao,项目名称:zVirtualScenes,代码行数:79,代码来源:WebApi2Plugin.cs


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