初学Windows服务/WCF和前端GUI实现问题

发布于 2024-10-22 03:11:42 字数 402 浏览 1 评论 0原文

我正在尝试找出实现此设计的最佳方法...以下是我正在尝试做的一些背景:

我有一个简单的数字 I/O 控制器,它通过以太网将数据发送到我的计算机。我有一个程序可以通过以太网接收这些数据。我想要一个单独的前端应用程序来在 GUI 中显示这些数据。我试图找出连接通过以太网获取 I/O 数据的程序以及将其显示为前端的程序的最佳方法。该接口应在计算机启动时运行,并在后台不断轮询 I/O。

我读过有关 Windows Communication Foundation (WCF) 的内容,这似乎是一个很好的方法。由于 Windows 服务会悄悄地持续轮询 I/O,并且连接到 WCF 接口的任何客户端都可以在 GUI 中呈现此数据。

我这一切都错了吗?这看起来是一个好方法吗?我的前端客户端将如何从 WCF 服务获取数据?

先感谢您。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2024-10-29 03:11:42

这正是我所做的——在 Windows 服务中托管 WCF 服务。 Windows服务就是进程; WCF 服务是完成工作的地方。

就我而言,我的基于 WCF 的 CollectionService 大部分时间都处于待命状态。我使用 WCF 来启动和停止收集器,因为 WCF 编程模型使这变得很容易。但是,为了将数据从收集器获取到 UI,我使用 TCP 套接字,而不是 WCF。我知道 WCF 有流模式,但是 (1) 我从未使用过它,并且 (2) 我相信以这种方式使用 WCF 会产生一定的开销。套接字对我来说只是一个舒适的后备,但我认为 WCF 可以工作。

如果您刚刚开始,可以参考这两个答案来使用 C# 启动并运行 Windows 服务。从那里,您只需创建 ServiceHost 并在 Windows 服务的 OnStart()OnStop() 回调中将其关闭, 分别。

如果您是 WCF 新手,请看一下这个 SO 问题。

学习 WCF 最新内容的好又简单的书籍/教程< /a>

还有一件事。在您从事此工作的过程中,您可能会发现您希望 WCF 服务在发生某些事情时向您的 UI 提供事件。例如,您可以提供一个事件来定期通知 UI 已接收的字节数。为此,我强烈推荐WCF大神之一Juval Lowy的这篇文章。

关于单向调用、回调和事件您需要了解的内容

他的发布-订阅框架可在他的网站 IDesign.net 上免费获得,同时还有其他几个可用的 WCF例子。

希望这有帮助。

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文