WCF WebApi 如何将请求 URI 映射到适当的服务类型/操作?

发布于 2024-11-16 14:57:35 字数 609 浏览 3 评论 0原文

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

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

  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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁梦 2024-11-23 14:57:35

通过使用 MapServiceRoute,代码实际上是在 ASP.NET 路由表中注册一个 ServiceHostFactory。因此,首先,请求到达 ASP.NET,然后将其定向到员工资源服务(这是 URL 可以映射到的唯一路由)。此时,WCF Web API 服务主机 (HttpConfigurableServiceHost) 将使用 UriTemplateTable 将请求分派到适当的操作:如果您有类似下面的代码,那就是将调用的操作:

[WebGet(UriTemplate = "/{employeeName}")]
public Employee Get(string employeeName);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文