How does WCF WebApi map a request URI to the appropriate service type / operation?

徘徊边缘 提交于 2019-12-06 12:07:05

问题


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 request comes in for http://server/employees/John

  1. 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.


回答1:


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);


来源:https://stackoverflow.com/questions/6446480/how-does-wcf-webapi-map-a-request-uri-to-the-appropriate-service-type-operatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!