简体   繁体   English

多个数据库的 WCF 配置

[英]WCF Configuration for multiple Databases

I am in the process of converting our win forms application to use a WCF service instead of client calls to a SQL database.我正在将我们的 win 表单应用程序转换为使用 WCF 服务而不是客户端调用 SQL 数据库。

Im not sure whats best practice but we have identical database schemas on about 600 databases.我不确定什么是最佳实践,但我们在大约 600 个数据库上有相同的数据库架构。

i was hoping to find a solution here where i in the startup of the winform application declare the WCF service to use this database.我希望在这里找到一个解决方案,我在启动 winform 应用程序时声明 WCF 服务以使用此数据库。 as of i'm trying to avoid in every single method to pass a parameter for what connection string to use.从我开始,我试图避免在每个方法中都为要使用的连接字符串传递参数。

i have some understanding of WCF but i know very little of "public declarations" and the connection context, and have not found any good examples for my scenario.我对 WCF 有一些了解,但我对“公共声明”和连接上下文知之甚少,并且没有找到任何适合我的场景的好例子。

is this even possible?这甚至可能吗?

if anyone can guide me in the right direction or hand me some sample code it would be very much appreciated!如果有人能指导我正确的方向或给我一些示例代码,我将不胜感激! :) :)

Thanks in advance提前致谢

WCF does support sessions. WCF 确实支持会话。 So you could pass which database you want to use in the first call, and all other calls would use the value in session.因此,您可以在第一次调用中传递要使用的数据库,而所有其他调用都将使用会话中的值。

See: http://msdn.microsoft.com/en-us/library/ms733040.aspx请参阅: http : //msdn.microsoft.com/en-us/library/ms733040.aspx

WCF is a strange API, in that you'll spend the first month not getting it at all and the next several months wondering how you couldn't get it. WCF 是一个奇怪的 API,因为第一个月你根本没有得到它,接下来的几个月会想知道你是怎么得到它的。 I can answer some of your questions.我可以回答你的一些问题。

  1. The best resource I know of is the Juval Lowry book, although I hear the Bustamante book is also very good.我所知道的最好的资源是 Juval Lowry 的书,虽然我听说 Bustamante 的书也很好。

  2. You can spin up the WCF service in Main() before you run the Form您可以在运行 Form 之前在 Main() 中启动 WCF 服务

  3. For the design you're talking about you will probably need to have a non-default constructor for your service.对于您正在谈论的设计,您可能需要为您的服务提供一个非默认构造函数。 This is a bit painful and I believe the Lowry book handles it.这有点痛苦,我相信洛瑞的书可以解决这个问题。 If not look at IInstanceProvider and IEndPointBehavior如果不看 IInstanceProvider 和 IEndPointBehavior

That being said, I don't really see how WCF fits into this design scheme.话虽如此,我真的不明白 WCF 如何适应这个设计方案。 Its really for communication between a client and server.它真正用于客户端和服务器之间的通信。 If you're planning on using it for an SOA type design there are other methods that are a lot cleaner and more light weight.如果您打算将它用于 SOA 类型的设计,那么还有其他更简洁、重量更轻的方法。 Dependency injection, etc. Can you give a more straightforward example of what you want to do perhaps?依赖注入等。你能举一个更直接的例子来说明你想要做什么吗? I would even suggest a class that simply wraps your database that you pass into all objects that need DB information instead of WCF.我什至建议一个类,它简单地包装您的数据库,您将其传递到需要数据库信息而不是 WCF 的所有对象中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM