Routing in WCF data services

删除回忆录丶 提交于 2019-12-13 16:26:53

问题


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

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!


回答1:


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

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



来源:https://stackoverflow.com/questions/8220099/routing-in-wcf-data-services

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