简体   繁体   English

WCF服务器和WCF服务之间的数据共享

[英]WCF Server and data sharing between WCF Services

I am trying to implement basic communicaton in WCF. 我正在尝试在WCF中实现基本通信。 So far I've been following this msdn tutorial: https://msdn.microsoft.com/en-us/library/ms734712%28v=vs.110%29.aspx 到目前为止,我一直在关注此msdn教程: https : //msdn.microsoft.com/zh-cn/library/ms734712%28v=vs.110%29.aspx

My problem : in the app there will be around 3 separate WCF Services (but contained in the same WCF Service Library project) for 3 different types of clients. 我的问题 :在应用程序中,将为3种不同类型的客户端提供大约3个单独的WCF服务(但包含在同一WCF服务库项目中)。

  1. I need to create some data structures that would be shared among all 3 WCF Services. 我需要创建一些在所有3个WCF服务之间共享的数据结构。 For example, I would like to keep track of connected clients and would like to have access to such list inside services to add to it, remove etc. Normally, the server app should hold such data and maintain it but I'm already a bit confused with all of the WCF abstraction. 例如,我想跟踪连接的客户端,并希望访问服务中的此类列表以添加,删除等。通常,服务器应用程序应保存并维护此类数据,但我已经有点与所有WCF抽象混淆。 Seems like all of the communication logic must be implemented in WCF Services. 似乎所有通信逻辑都必须在WCF服务中实现。 Server app just creates and opens the ServiceHost objects associated with the Services and there's no way for it to expose specific data to the Services(which could also modify the data)? 服务器应用程序仅创建并打开与服务相关联的ServiceHost对象,并且无法将特定数据公开给服务(这也可能会修改数据)吗? So the question is where and how to share data between multiple WCF Services? 因此,问题是在多个WCF服务之间共享数据以及在何处共享?

  2. I need to keep track of how often some messages arrive. 我需要跟踪一些消息到达的频率。 How could this be done in a WCF Service? 在WCF服务中如何做到这一点? Create a separate thread in service's constructor and there monitor some fields that service would update after receivng given message? 在服务的构造函数中创建一个单独的线程,并监视接收到给定消息后服务将更新的某些字段? Would that be a viable solution? 那是一个可行的解决方案吗?

Are WCF services actually the way to go or there's some better approach? WCF服务实际上是要走的路,还是有更好的方法? If you could give me some hints and keywords necessary to accomplish what I've described, I would be really grateful! 如果您能给我一些完成我所描述的必要的提示和关键字,我将不胜感激!

What you want to do is beyond the scope of WCF itself. 您想要做的事超出了WCF本身的范围。 You need a data access layer where you can keep the state of your application. 您需要一个数据访问层,您可以在其中保留应用程序的状态。

There are many ways to do it depending on the situation. 根据情况,有很多方法可以做到这一点。 It could very well be a simple singleton object with a List < Client > in it, so you just store these connections in RAM. 它很可能是一个带有List <Client>的简单单例对象,因此您只需将这些连接存储在RAM中即可。 It could be some dependency IStorage, which you inject with IoC. 可能是某些依赖关系IStorage,您可以通过IoC注入它。 You could use a database directly. 您可以直接使用数据库。

Basically make another class which is responsible for storing these connections. 基本上制作另一个负责存储这些连接的类。 Then allow your WCF services to access that class. 然后,允许您的WCF服务访问该类。

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

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