Savail
Savail

Reputation: 867

WCF Server and data sharing between WCF Services

I am trying to implement basic communicaton in WCF. So far I've been following this msdn tutorial: https://msdn.microsoft.com/en-us/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.

  1. I need to create some data structures that would be shared among all 3 WCF Services. 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. Seems like all of the communication logic must be implemented in WCF Services. 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)? So the question is where and how to share data between multiple WCF Services?

  2. I need to keep track of how often some messages arrive. How could this be done in a WCF Service? 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? If you could give me some hints and keywords necessary to accomplish what I've described, I would be really grateful!

Upvotes: 0

Views: 647

Answers (1)

Eiver
Eiver

Reputation: 2635

What you want to do is beyond the scope of WCF itself. 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. It could be some dependency IStorage, which you inject with 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.

Upvotes: 1

Related Questions