Reputation: 797
I have a WCF service in which I have long running methods like get and process some kind of data and then return it to client. I have tried to use contracts similar to following
Task<string> ServiceMethod(string message);
The problem is if I want to return the same data to multiple clients from the service then how can I do it (How do I get and store information about clients who are requesting data).
Also if I need to call a background worker from the above method then how do I process in the runworker_completed and return the result to the above.
Additional info
The returning of same data to multiple clients is only in case the clients request the same data but since it takes time to get and process it so whenever it is available I want to return to all the clients who have requested it.
Upvotes: 0
Views: 135
Reputation: 797
I have stored a cache of Task in the service with the keys requested. Whenever the task for that key is completed I send back tasks to all the clients which had requested the same key. Also for already existing functions with event based completion I have used TaskCompletionSource and stored it in the cache and again using it to send async response.
Upvotes: 0
Reputation: 1269
if I understand your question correctly, you want the service to callback clients when it finishes a long running process that generates data. As you have to take care of multiple clients, I would recommend that you use Duplex WCF. A duplex service contract provides for calling back a method on invoking client. The following code project link is good example for Duplex and has a lot more details
http://www.codeproject.com/Articles/491844/A-Beginners-Guide-to-Duplex-WCF
Note that you should have your own logic for maintaining the list of callback channels
Upvotes: 1