2

I have a tcp WCF service that is meant to calculate certain prices and put them into a queue for the client to pick up and to display.

The first thing that came to my mind was the Producer/Consumer pattern. The WCF Service produces the prices and puts them into a queue. The client would then consume any workitems ready in the queue.

Looking at Albahari's BlockingCollection example, how he explains producer/Consumer pattern, I can't get my head around it.

var pcQ = new PCQueue (1);
Task task = pcQ.EnqueueTask (() => Console.WriteLine ("Easy!"));

If I run this on the WCF service I have put a task in the queue to be processed, fair enough. But once the task is finished on the service side, how do I push the price to the client automatically? or is that not something I could do with a tcp WCF service?

MattC
  • 3,984
  • 1
  • 33
  • 49
Houman
  • 64,245
  • 87
  • 278
  • 460
  • I don't have personal experience in WCF, so I'll limit this to a comment/link, but look here: http://msdn.microsoft.com/en-us/library/ms789048.aspx – Joel Coehoorn Feb 17 '14 at 18:17

2 Answers2

2

For your problem I can think in two solutions:

The First: in your Task you put the push logic to send the result in your active connection, but... you have to build all the push environment for that.

The second: when you finish your task you could put the result in another endpoint to the client and, in the client, you build a logic to ask to the server "did you finished my task? What´s the answer?"

Ricardo Momm
  • 107
  • 6
0

Sounds like you want to be making use of WCF callbacks.

Here is a question that might help guide you to what you want to do.

The producer/consumer pattern is valid. The WCF callback is just an implementation detail in this case.

Community
  • 1
  • 1
MattC
  • 3,984
  • 1
  • 33
  • 49
  • Thanks for the link. Unfortunately this isn't exactly what I was thinking of. In his example he calls `proxy.DoSomething();` and then the server calls back. Thats not a push notification, its a callback on a pull. I have the feeling thats impossible with tcp. I might have to read up that MSMQ article. – Houman Feb 17 '14 at 20:37
  • The client need only call `Connect()` in a one way operation. The server can then simply store the context and then when which ever thread is handling the queue pulls off a new price the WCF services can take that price and call back on the client context. My point was that `CallbackContract` is how you can do this not specifically the implementation in the link. Yes reentrant calls would not work in your case. It's no different then a chat program really. – MattC Feb 18 '14 at 09:34