WCF WebApi 如何将请求 URI 映射到适当的服务类型/操作?
WCF REST(和 WCF WebApi)如何将 Uri 映射到正确的服务终结点?
在 WCF WebApi Preview 4 的上下文中: 在自定义委托通道内,我想根据传入的 HttpRequestMessage.RequestUri 查找关联的路由前缀或服务类型。
例如,
RouteTable.Routes.MapServiceRoute<ManagersResource>("employees/managers", config);
RouteTable.Routes.MapServiceRoute<EmployeesResource>("employees", config);
假设有一个请求 http://server/employees/John
- WCF 如何将其映射到正确的终点?
当ResourceFactoryProvider
实例化时,它已经知道具体的服务类型。我似乎无法追踪 Uri 和路由表路由之间的解析发生在哪里。
非常感谢。
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
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过使用
MapServiceRoute
,代码实际上是在 ASP.NET 路由表中注册一个ServiceHostFactory
。因此,首先,请求到达 ASP.NET,然后将其定向到员工资源服务(这是 URL 可以映射到的唯一路由)。此时,WCF Web API 服务主机 (HttpConfigurableServiceHost
) 将使用UriTemplateTable
将请求分派到适当的操作:如果您有类似下面的代码,那就是将调用的操作:By using the
MapServiceRoute<TService>
, the code is actually registering aServiceHostFactory
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 theUriTemplateTable
to dispatch the request to the appropriate operation: if you have something like the code below, that's the operation which will be called: