8

I know there are tutorials out there regarding WCF callbacks and events, but I'm having trouble getting them to actually work, or they're too complex. I'm a real beginner, so I would love to hear if anyone knows of any solid beginner tutorials that are aimed to what I'm trying to specifically figure out at the moment. Please forgive me if I use the wrong terminology (and please correct me), like I said I'm a beginner.

The Problem:

enter image description here

It might look more complicated than it really is. Basically what I'm trying to accomplish is:

  1. A Host with some local memory (lets say an array of 5 integers) and running a WCF service. that will listen for queries from the client AND fire an update (events?) to the client when one of these integers are changed (from an external source, such as user input via command prompt and Set()).
  2. A Client that can make direct queries to return one of these five integers or subscribe to a particular index of the host array.

What I Can Do:

I can set up the connection, but my service is limited to standalone functions. The client can make "queries", but is limited to remote function calling (such as "add", where all parameters are passed with the function and the processing is done internally).

What I'm Trying To Figure Out:

  1. How can I access some variables held in the host memory from the service contract functions? For example, how can I call a method from the client GetInt() that would simply return something stored in the application memory on the host?
  2. How can I push a "message" to the client from the host? For example, in the host, call TellClient(int x), which would call some function on the client side? Is this possible without running a service on both sides?

TLDR:

Host : Service <-> Client. Is there a way to push data (simply an int) to the client without the client calling any functions (no polling or queries)? Is there a way to have the WCF service access variables stored in instance of the host application without using static members? Can this be accomplished in a simple way?

Thanks for your help and time, I know I wrote a book. If anyone knows of any nice tutorials, please point me to them. But PLEASE - Don't point me to the Add(int x, int y) example where the client just calls add on the host and returns the result - I've already done this a few times over and it's not helping me grasp the real functionality of WCF. I'm really not trying to accomplish anything serious at this point, I'm really trying to keep it simple so I can learn what WCF can do, and I'm not finding the documentation to be very helpful. Thanks again everybody.

jgauffin
  • 95,399
  • 41
  • 227
  • 352
Softerware
  • 2,447
  • 2
  • 13
  • 20

2 Answers2

7

Generally WCF is used in a request reply way, where clients make requests; and server replies. What you want to achieve is a "push and pull" service; or in Microsoft terms a duplex service.

In duplex services clients just connect to a service and service registers them into some internal list. And whenever an event(or something else) arises, it sends a message to the registered clients. The key terminology for WCF in the context of your question is "duplex services"(you may google it find many results). You may refer to the following tutorials;msdn or codeproject

For the second part of your question, the answer is yes. But this is not that simple. You need to write some "wcf behaviors", for instance an IInstanceProvider may help you. For all requests, you may just create the service instance yourself, with desired parameters injected into the service instance. Referring to the following may help: stackoverflow or msdn.

The question is a bit broad thus I am not 100% sure whether this is a direct answer. But at least using the keywords provided you may find the right direction.

Community
  • 1
  • 1
daryal
  • 14,035
  • 4
  • 35
  • 54
  • This is great information, thanks a lot for your help - they terminology and keywords were what I didn't know, so I couldn't find what I was looking for via searching. I'm not afraid to do the research. I've already found something far closer to what I'm looking for (by looking for duplex services). Thanks again! – Softerware Jun 04 '12 at 15:23
3

Have you tried this article yet? http://msdn.microsoft.com/en-us/magazine/cc163537.aspx#S6. I thought it was a decent explanation on callbacks. It discusses a publish/subscribe framework which is a solution to your "no polling or queries" requirement.

insipid
  • 3,118
  • 3
  • 24
  • 36