开发者

Beginner Windows Service / WCF and front end GUI implementation Question

开发者 https://www.devze.com 2023-02-16 03:48 出处:网络
I am trying to figure out the best way to approach this design... Here is some background of what I\'m trying to do:

I am trying to figure out the best way to approach this design... Here is some background of what I'm trying to do:

I have a simple digital I/O controller that sends data to my computer via Ethernet. I have a program that can receive this data over Ethernet. I would like a开发者_StackOverflow中文版 separate front end application that presents this data in a GUI. I am trying to figure out the best way to interface the program that grabs the I/O data over Ethernet, and the program that displays this as the front end. This interface should run whenever the computer boots and constantly poll the I/O in the background.

I've read about Windows Communication Foundation (WCF) and this seems like a nice way to do this. As the windows service would quietly keep polling the I/O and any clients that attach to the WCF interface can present this data in a GUI.

Am I going about this all wrong? Does this seem like a good way to do things? How will my front end clients grab the data from the WCF service?

Thank you in advance.


That's precisely the way I have done it - hosting a WCF service in a Windows service. The Windows service is the process; the WCF service is where the work is done.

In my case, my WCF-based CollectionService is on standby most of the time. I use WCF to start and stop the collector because the WCF programming model makes this easy. However, to get the data from the collector to the UI, I use a TCP socket, not WCF. I know that WCF has a streaming mode, but (1) I've never used it and (2) I believe there is some amount of overhead using WCF this way. The socket is simply a comfortable fallback for me, but I think WCF could be made to work.

If you're just starting, you can refer to these two answers for getting your Windows service up and running using C#. From there, you'll just need to create the ServiceHost and close it in the OnStart() and OnStop() callbacks of your Windows service, respectively.

  • Easiest language for creating a Windows service
  • How to make a .NET Windows Service start right after the installation?

If you are new to WCF, take a look at this SO question.

Good and easy books/tutorials to learn WCF latest stuff

One more thing. In the course of your work on this, you may find that you want the WCF service to provide events to your UI when certain things occur. For example, you might provide an event that periodically notifies the UI of the number of bytes that have been received. For this, I would strongly recommend this article by Juval Lowy, one of the WCF gods.

What You Need To Know About One-Way Calls, Callbacks, And Events

His Publish-Subscribe Framework is available for free at his website, IDesign.net, along with several other working WCF examples.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消