如何在 WinForm 中最好地公开方法?

发布于 2024-12-03 00:22:48 字数 483 浏览 2 评论 0原文

我有一个 C# 表单应用程序,它使用串行端口连接到电子设备。 “SerialCommunicationManager”类在应用程序启动时连接到串行端口,并处理与设备通信的脏活。

我想公开以下方法。

  • Write()
  • SerialDataReceived 事件
  • SerialDataTransmissed 事件

我想公开其方法,主要是在同一台计算机上运行的本地网站,但将来我想也需要外部应用程序。

公开功能的最简单方法是什么?

  • TCPIP 客户端服务器?
  • 网络服务? (我可以在 WinForm 中创建 Web 服务吗?)
  • 其他?

非常感谢

//David

在此处输入图像描述

I have a C# form application that connects to a electronic device using the serial port.
The class "'SerialCommunicationManager'" hooks up to the serial port on application startup and handles the dirty business of talkning to the device.

What I would like is to expose the following methods.

  • Write()
  • SerialDataReceived event
  • SerialDataTransmitted event

Primarily a local website running on the same machine is the one I want to expose the methods for, but in the future I imagine the need for external applications as well.

What is the easiest way to expose the functionality?

  • TCPIP client server?
  • Web service? (Can I create a web service inside a WinForm?)
  • other?

Big thanks

//David

enter image description here

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

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

发布评论

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

评论(3

別甾虛僞 2024-12-10 00:22:48

我建议自托管 WCF 服务。这为您提供和公开此信息的方式提供了巨大的灵活性,包括能够通过配置更改其提供服务的方法。

I would recommend self-hosting a WCF Service. This provides you a huge amount of flexibility in terms of how you serve and expose this information, including being able to change the method by which its served via configuration.

魄砕の薆 2024-12-10 00:22:48

在我看来,如果你想正确地做到这一点,你应该分解你的表单应用程序,并创建:

  • 一个处理串行通信的服务,并通过远程处理
  • 一个使用 API 的表单应用程序公开一个 API,并创建一个方法 然后,根据

您网站的位置,如果它将保持本地(或本地 - LAN 附近):

  • 网站应使用远程处理来调用服务

,否则,如果您计划拥有多个网站:

  • 托管 Web 服务在将包装远程处理的 IIS 中 将使用 Web 服务的API
  • 网站

但是,如果要做的工作太多 - 只需使用远程处理并向网站公开所需的方法即可。

It seems to me, that if you would like to do it properly, you should break apart your forms app, and create:

  • a service that handles serial comm and has an API exposed through remoting
  • a Forms app that uses the API and makes a way with the service

Then, depending on the locality of your web site, if it will remain local (or near local - LAN):

  • web site should use remoting to call the service

else, if you plan to have multiple web sites:

  • web service hosted inside the IIS that will wrap remoting API
  • web site that will use web service

However, if it is too much work to do - just use remoting and expose needed methods to the web site.

不甘平庸 2024-12-10 00:22:48

在最近的一个项目中,我们做了以下工作:

  • 编写一个与电子设备通信的控制台应用程序(或 Windows 服务,具体取决于您的需要)。
  • 使控制台应用程序托管 .NET 4 WCF 服务。
  • 编写一个 .NET 2 Windows 窗体应用程序以通过 Web 服务与控制台应用程序进行通信。

在这种情况下,我可以想象您提到的网站也使用 Web 服务 (WSDL) 与控制台应用程序进行通信。

In a recent project we did the following:

  • Write a Console application (or Windows Service, depending on your needs) that communicates with the electronic device.
  • Make the Console application host a .NET 4 WCF service.
  • Write a .NET 2 Windows Forms application to communicate through Web Services with the console application.

In this context, I could imagine the website you are mentioning to also use Web Services (WSDL) to communicate with the Console application.

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