动态添加 WCF 数据服务端点
我一直在研究 oData 和 WCF DataServices,我认为它非常适合我的项目。
然而,我们的每个客户都有自己的数据库。
那么,有没有一种方法可以动态创建一个可以指向数据库的 WCF 端点。 所有数据库的架构都是相同的。
例如: Client1 需要 DB1,他们将使用 URL:https://webservice.com/wcf/Client1 这将使用 DB1
Client2 需要 DB2,他们将使用 URL: https://webservice.com/wcf/Client2使用 DB2
Client3 需要 DB3,他们将使用 URL: https://webservice.com/wcf/Client3 它将使用 DB3
或者我需要能够传递要连接到的数据库,但我不知道如何使用 WCF 数据服务来做到这一点。,我过去已经使用普通的 WCF 服务完成了它
它们需要是动态的,因为我们一直在添加新客户,并且我们有一个用于创建数据库的自动化流程。
我知道我可以为每个数据库创建一个 Web 服务,但使用 1 个 Web 服务维护起来会容易得多。
I've been researching oData and WCF DataServices and I think it would work great for my project.
However, each of our clients have their own database.
So, is there a way to dynamically create a WCF endpoint that I could point to a database.
The schema for all the databases are identical.
For Example:
Client1 needs DB1, they would use the URL: https://webservice.com/wcf/Client1 which would use DB1
Client2 needs DB2, they would use the URL: https://webservice.com/wcf/Client2 which would use DB2
Client3 needs DB3, they would use the URL: https://webservice.com/wcf/Client3 which would use DB3
Or I would need to be able to pass which database to connect to, but I don't how i would do that with WCF Data Services., I've done it with normal WCF services in the past though
They need to be dynamic because we are adding new clients all the time and we have an automated process for creating databases.
I know I could create a web service per database, but it would be much easier to maintain with 1 web service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案。
我可以将 Web 服务中的连接字符串作为标头传递,而不是创建多个端点。
这是示例代码。它确实很容易实现并且效果很好。
http://social.msdn .microsoft.com/Forums/en-NZ/adodotnetdataservices/thread/2eb0e7a8-10c5-4c6c-80b8-23cb39161345
I found the answer.
Rather then creating multiple endpoints, I can just pass the Connection String from the webservice as a header.
Here's example code. It's really easy to implement and works great.
http://social.msdn.microsoft.com/Forums/en-NZ/adodotnetdataservices/thread/2eb0e7a8-10c5-4c6c-80b8-23cb39161345