How does WCF WebApi map a request URI to the appropriate service type / operation?
How does WCF REST (and WCF WebApi) map a Uri to the correct service endpoint?
Within the context of WCF WebApi Preview 4: Inside a custom delegating channel, I would like to find the associated route prefix or service Type based on the incoming HttpRequestMessage.RequestUri.
So for instance,
RouteTable.Routes.MapServiceRoute<ManagersResource>("employees/managers", config);
RouteTable.Routes.MapServiceRoute<EmployeesResource>("employees", config);
Say a requ开发者_JAVA技巧est comes in for http://server/employees/John
- How does WCF map this to the correct endpoint?
By the time the ResourceFactoryProvider
has been instantiated, it already knows the concrete service type. I can't seem to trace where the resolution happens between the Uri and routing table routes.
Much thanks in advance.
By using the MapServiceRoute<TService>
, the code is actually registering a ServiceHostFactory
in the ASP.NET routing table. So first, the request arrives at ASP.NET, and that directs it to the service EmployeesResource (which is the only route to which the URL can be mapped). At that point, the WCF Web API service host (HttpConfigurableServiceHost
) will use the UriTemplateTable
to dispatch the request to the appropriate operation: if you have something like the code below, that's the operation which will be called:
[WebGet(UriTemplate = "/{employeeName}")]
public Employee Get(string employeeName);
精彩评论