views:

161

answers:

1

So I've created a series of objects that interact with a piece of hardware over a serial port. There is a thread running monitoring the serial port, and if the state of the hardware changes it updates properties in my objects. I'm using observable collections, and INotifyPropertyChanged.

I've built a UI in WPF and it works great, showing me real time updating when the hardware changes and allows me to send changes to the hardware as well by changing these properties using bindings.

What I'm hoping is that I can run the UI on a different machine than what the hardware is hooked up to without a lot of wiring up of events. Possibly even allow multiple UI's to connect to the same service and interact with this hardware.

So far I understand I'm going to need to create a WCF service. I'm trying to figure out if I'll be able to pass a reference to an object created at the service to the client leaving events intact. So that the UI will really just be bound to a remote object.

Am I moving the right direction with WCF?

Also I see tons of examples for WCF in C#, are there any good practical use examples in VB that might be along the lines of what I'm trying to do?

+1  A: 

No, WCF is a message based system - you pass around serialized (text/xml) messages. There's no "object references" that you can pass around.

The client has a proxy, which gives you the ability to "call" the service method. The WCF runtime then captures the parameters to that call, packages them up in a serialized message, and sends that message across the wire.

There is no direct connection between the client and the server - the client can't "reach over" to the service to get a remote object, nor can the service go back to the client to find out who called it or anything like that.

All that you want to send to the service must be part of either the message itself, or the headers that accompany the message.

Those messages must conform to the XML schema standard, which again means: only concrete non-generic types. You can't pass around interfaces, you cannot pass references - only concrete types made up of basic types such a string, int, datetime etc.

Update: maybe you need to check out the publish/subscribe (pub/sub for short) pattern - which you can also build using WCF. This would allow you data collection machine to publish its data on a regular basis or whenver it changes, and any number of subscribers could be notified of those changes.

Check out some of those articles - googling or binging for "WCF pub sub" will definitely turn out quite a few more!

marc_s
So if this is not possible, do I need to take a step back and rethink how I'm going to accomplish this goal possibly having the object live on the client and just messages from the serial port to be passed over the wire, or is there another technology I should be looking into that would allow me to access .net objects that live on the host as if they were local to the UI on the client?
zimmer62
I think you need to rethink your architecture - design it so that your client-side object gets updated (its data fields) from a service call - but not the reference per se - just the data fields.
marc_s
I feel like this kind of stinks and works against the idea behind data binding in the UI when the data isn't coming from a local object. So on the server side I'd have to watch if anything changes and then force the client to reload the object, or at least the changing field? It sounds like more work than it's worth. I feel like WCF is a step backwards from remoting in this aspect.
zimmer62
Maybe so - WCF was designed primarily to be an interoperable services platform - to be able to talk to disparate clients, also non .NET clients. To cover all those requirements, I guess message based systems seemed like the way to go - all the object remoting approaches (like DCOM and Corba) have largely failed in trying to establish a "distributed object world".
marc_s
Okay.. well it looks like I'm going to have to take 10 medium steps back and 100 baby steps forward, as my approach seems to have some flaws in it. I felt like my design was really solid when using it all from the same machine. As soon as I decided to try and separate the business and ui layers across boundaries my entire design method falls apart.I can't seem to figure out a good model for what I'm trying to do.
zimmer62