如何在 WinForm 中最好地公开方法?
我有一个 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议自托管 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.
在我看来,如果你想正确地做到这一点,你应该分解你的表单应用程序,并创建:
您网站的位置,如果它将保持本地(或本地 - LAN 附近):
,否则,如果您计划拥有多个网站:
但是,如果要做的工作太多 - 只需使用远程处理并向网站公开所需的方法即可。
It seems to me, that if you would like to do it properly, you should break apart your forms app, and create:
Then, depending on the locality of your web site, if it will remain local (or near local - LAN):
else, if you plan to have multiple web sites:
However, if it is too much work to do - just use remoting and expose needed methods to the web site.
在最近的一个项目中,我们做了以下工作:
在这种情况下,我可以想象您提到的网站也使用 Web 服务 (WSDL) 与控制台应用程序进行通信。
In a recent project we did the following:
In this context, I could imagine the website you are mentioning to also use Web Services (WSDL) to communicate with the Console application.