Dynamically adding WCF Data Services Endpoints

谁都会走 提交于 2019-12-13 00:25:34

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/4718537/dynamically-adding-wcf-data-services-endpoints

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