动态添加WCF数据服务端点 [英] Dynamically adding WCF Data Services Endpoints

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

问题描述

我一直在研究的OData和WCF DataService的,我认为它会工作非常适合我的项目。

不过,我们的每一个客户都有自己的数据库。

那么,有没有一种方法可以动态地创建一个WCF终结,我可以指向一个数据库。 对所有的数据库的模式是相同的。

例如: 客户端1需要DB1,他们会使用的网址: https://webservice.com/wcf/Client1 这将使用DB1

客户机2需要DB2,他们会使用的网址: https://webservice.com/wcf/Client2这将使用DB2

Client3需要DB3,他们会使用的网址: https://webservice.com/wcf/Client3这将使用DB3

或者我需要能够通过连接到数据库,但我不我会怎么做,与WCF数据服务,我用正常的WCF服务,但

他们需要的是动态的,因为我们正在增加新的客户所有的时间,我们必须创建数据库的自动化流程。

我知道我可以创建每个数据库的Web服务,但它会更容易与1 Web服务维护。

解决方案

我找到了答案。

相反然后创建多个端点,我可以通过连接字符串从WebService作为标题。

下面的例子code。这真的很容易实现伟大工程。

<一个href="http://social.msdn.microsoft.com/Forums/en-NZ/adodotnetdataservices/thread/2eb0e7a8-10c5-4c6c-80b8-23cb39161345" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-NZ/adodotnetdataservices/thread/2eb0e7a8-10c5-4c6c-80b8-23cb39161345

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.

解决方案

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

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

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