本文整理汇总了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);
}
示例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");
}