tags:

views:

69

answers:

1

Scenario

  • So I've taken an example of a distributed application in WCF that implements the Observer pattern.
  • Ihave put the server-side into a windows service and added some classes to do some calculations, which I intend to pass the results back to the client.

The solution is made up of 3 projects.

  • Server-Side Windows Service - Processes all the data/Performs calculations.
  • Common Objects Class Library.
  • Client-Side Windows Forms Application.

They connect and exchange data using a WCF Service that implements the Observer pattern to allow for two-way data exchange.

On The Server-Side:

I've got 3 classes:

  1. Class one calculates X.
  2. Class two calculates Y.
  3. Class three calculates Z.

The data from these 3 calculations is then published via the WCF Service to the Client-Side.

On The Client-Side:

Here's the TRICKY part………..

I want each set of data from each of these 3 classes to be displayed on a GridControl on a DIFFERENT Form.

So it will be as follows:

  1. Class X data will be published to the MainForm.
  2. Class Y data will be published to the YForm.
  3. Class Z data will be published to the Zform.

The Client application, when first run, will show only the MainForm, but it will contain a menu bar to open the Yform and Zform.

Thoughts:

  • What do you think the best way to do this is?
  • Do I publish all the data to one central class and then invoke the dictionaries bound to the grid controls on each different form to update the data?
  • Or is there another way?

Appreciate the help.

+1  A: 

Option 2 in your list would work, publish to a central class on the client and have the other forms query this class for the info. I would suggest a Publish/Subscribe pattern rather than the observer (I presume you will implement this with Duplex bindings), as it is a less coupled implementation which scales better.

This way the service will just publish info to subscribing clients.

You can implement this by hosting WCF response services on the client form, this way when one of your calculation services publishes a result, the service hosted on the WinForm can subscribe and receive this event.

If you have a requirement to keep the forms open and update them in real time you can have each form that needs data to host a service on the form, and just subscribe to different events. You can then synchronize (synchronization context) onto the UI thread and update the grid in real time i.e stock price updates.

I recommend Juval Lowy's book Programming WCF Services to help explain the concepts and provide a reference implementation of Publish/Subscribe, hosting services on forms and synchronization context.

MetalLemon
Ok, I've implemented PubisherSubscriber and have made use of a custom BindingDictionary object to refresh my grid as data is published. Since the form that contains the grid implemented ISubscription, does that mean ALL of the forms that want to receive data will have to implement this interface?
Goober
The form is the service and hosts itself, so if a form wants to receive messages it will need to host that Interface. You can also implement a single form as a Form Manager that has multiple UI threads and pumps messages out to its own set of windows. See Chapter 8.6 in Programming WCF Services.
MetalLemon