动态选择连接实体框架休息
我有一个非常简单的实体框架 (.edmx) 文件和一个 .svc 休息服务。
CRUD 操作一切正常。
我有许多共享完全相同架构的数据库。
我的下一步是让客户端传递一个参数,该参数可以是连接字符串或标识用户的其他值,以便服务从正确的数据库提供数据。
现在,唯一的参数是我在数据模型中看到的 ServiceRoot 的 uri
,我可以将连接字符串传递给 inn,但是如何在不创建许多服务文件的情况下从客户端执行此操作。
I have a very simple entity framework (.edmx) file, and a .svc rest service.
Everything works fine for CRUD operations.
I have many databases thats shares the exactly same schema.
My next step is to let the client pass inn a parameter that could be the connection string or some other value identifying the user so that the service serves data from the correct database.
Now, the only parameter is the uri for the ServiceRoot
I see in the datamodel that I can pass inn a connection string, but how can i do this from the client without making many service files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您正在使用 WCF 数据服务来公开 edmx 文件。我不是这个工具集的专家,但我怀疑唯一直接的方法是为每个数据库创建一个服务。
这是一个很好的问题,我希望在未来的 WCF HTTP 堆栈中能够解决这个问题。
与此同时,也有一些积极的消息传来。我过去曾尝试过创建大量服务主机(大约 1000 个),实验表明启动效率非常高,并且不会消耗大量 RAM。关键是用代码而不是通过配置文件创建服务主机。显然,您不想手动编写包含数千个服务条目的 XML 配置文件!
这可能不是理想的解决方案,但我相信它会起作用。
I am assuming you are using WCF Data Services to expose the edmx file. I am no expert in this toolset but I suspect the only direct way is to create a service for each database.
This is a great question and it is a scenario that I hope will be addressed in the future WCF HTTP stack.
In the meanwhile, there is some positive news. I have experimented in the past with creating a large number of service hosts (around 1000) and my experimentation showed that it was quite efficient to start up and did not consume large amounts of RAM. The key is to create the service hosts in code rather than via the config files. Obviously, you don't want to be hand writing an XML config file with thousands of service entries in it!
It may not be the ideal solution but I believe it would work.
如果您使用的是 WCF 数据服务,您应该能够传递标识要在 HTTP 请求中使用的数据源的信息。作为 URL 中的自定义选项或作为自定义 HTTP 标头(我可能会使用自定义标头,因为从客户端使用它更容易)。
根据您托管服务的方式,您应该能够访问服务器上请求的标头。您可以使用 ASP.NET 方式来执行此操作(静态变量),也可以挂钩 WCF 数据服务的处理管道,这也允许您访问这些标头。
If you're using WCF Data Services you should be able to pass the information identifying the data source to use in the HTTP request. Either as a custom option in the URL or as a custom HTTP header (I would probably use the custom header as it's much easier to work with from the client).
Depending on the way you host the service you should be able to access the headers of the request on the server. You can use the ASP.NET way to do this (static variables), or you can hook into the processing pipeline of the WCF Data Services which should allow you to access those headers as well.