This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoutes.cs
52 lines (37 loc) · 1.6 KB
/
Routes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Activation;
using System.Text;
using System.Web.Routing;
using Microsoft.ApplicationServer.Http;
using Microsoft.ApplicationServer.Http.Activation;
using Orchard.Mvc.Routes;
using Orchard.Wcf;
using myRestfulModule.Services;
namespace myRestfulModule
{
public class Routes : IRouteProvider {
private static readonly ServiceRoute _route = MapServiceRoute(typeof (PeopleService), "myRestfulModule/People");
public IEnumerable<RouteDescriptor> GetRoutes() {
return new[] {
new RouteDescriptor {
Priority = 1,
Route = _route
}
};
}
public void GetRoutes(ICollection<RouteDescriptor> routes) {
foreach (var routeDescriptor in GetRoutes())
routes.Add(routeDescriptor);
}
private static ServiceRoute MapServiceRoute(Type serviceType, string routePrefix, HttpConfiguration configuration = null, object constraints = null, bool useMethodPrefixForHttpMethod = true)
{
if (configuration == null)
configuration = new WebApiConfiguration(useMethodPrefixForHttpMethod);
var serviceHostFactory = new HttpServiceHostFactory { Configuration = configuration };
var webApiRoute = new WebApiRoute(routePrefix, serviceHostFactory, serviceType) { Constraints = new RouteValueDictionary(constraints) };
return webApiRoute;
}
}
}