WCF数据服务中的路由 [英] Routing in WCF data services

查看:66
本文介绍了WCF数据服务中的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在针对多租户数据库的EF 4.1代码优先数据模型之上创建WCF数据服务。为了执行访问多租户的规则,我想要求将字符串ID(这是我们所有基于MVC的REST服务所必需的)作为URL路由的一部分传递。因此,例如,现在我有一条这样的服务路线:

I am creating a WCF data service on top of a EF 4.1 code first data model that goes against a multi-tenant database. In order to enforce the rules of accessing the multi-tenancy I want to require a string id (that is required by all of our MVC-based REST services) be passed as part of the url route. So, for example, right now I have a service route like this:

http://mysample.net/mysamplesvc.svc/Users

这将返回带有w / oa过滤器的db中的所有用户。我想按要求对客户端进行分区,方法是要求将客户端ID作为以下请求的一部分传递:

That returns all users in the db w/o a filter. I want to partition this by client by requiring the client id be passed as part of the request like this:

http://mysample.net/mysamplesvc.svc/client123/Users

如果没有传入或无效,我将按要求处理。但是,我在任何地方都看不到这样的示例。我认为我一定搜索不正确,因为这似乎很常见。

If it is not passed-in or is invalid I will handle it as required. However, I do not see any example like this anywhere. I think I must be searching incorrectly as this seems like a pretty common scenario.

TIA!

推荐答案

位于 http:/的示例服务/services.odata.org/(S(readwrite))/OData/OData.svc/ 进行此操作(它为URL中的每个(S(...))创建数据的新实例)。

The sample service at http://services.odata.org/(S(readwrite))/OData/OData.svc/ does this (it creates a new instance of the data for each (S(...)) in the URL).

服务代码是此页面上的最后一个示例: http://www.odata.org/ecosystem#samplecode

The service code is the last sample on this page: http://www.odata.org/ecosystem#samplecode

这篇关于WCF数据服务中的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆