简体   繁体   English

如何在ASP.NET和桌面应用程序之间交换数据?

[英]How to exchange data between ASP.NET and Desktop app?

I have (maybe not, ups) simple question about exchange data between that two platforms: ASP.NET and desktop app (best choose for my idea is WinForm, but can be console too). 关于这两个平台之间的数据交换,我有一个简单的问题(也许不是ups):ASP.NET和桌面应用程序(我的想法的最佳选择是WinForm,但也可以是控制台)。

My project in my mind: 我脑海中的项目:

  1. ASP.NET Core MVC app ASP.NET Core MVC应用
  2. Desktop app for share COM ports 共享COM端口的桌面应用程序

I have embedded system [STM32] on Virtual COM so I wanna only send/get data from this and send/get orders from server 我在虚拟COM上具有嵌入式系统[STM32],所以我只想从中发送/获取数据,并从服务器发送/获取订单

Send orders via POST/GET etc. is easy, I know.. But! 通过POST / GET等发送订单很容易,我知道..但是! I don't have idea how to send orders to my desktop app, without user interferences. 我不知道如何在没有用户干预的情况下将订单发送到我的桌面应用程序。

I only open this app in background and what I say "only for share port" 我只在后台打开此应用,然后说“仅用于共享端口”

There are numerous alternatives that you could use to accomplish this. 您可以使用许多替代方法来完成此任务。 As a general field, this is called Interprocess Communication (IPC). 作为一般领域,这称为进程间通信(IPC)。

From all approaches, I find embedding a web server into a Winforms application the most flexible and easier solition but please, bear in mind that it's my personal choice. 通过所有方法,我发现将Web服务器嵌入到Winforms应用程序中是最灵活,更轻松的方法,但是请记住,这是我个人的选择。 I'll try giving you other possible solutions on this post, though: 不过,我会在这篇文章中尝试为您提供其他可能的解决方案:

1. Embedd a server within your Winforms application 1.在您的Winforms应用程序中嵌入服务器

This is my personal choice. 这是我个人的选择。 You can digg into this topic by searching more about embedding a HTTP server into Winforms but here are some links that might give a direction on this: 您可以通过搜索有关将HTTP服务器嵌入Winforms的更多信息来深入了解此主题,但是以下一些链接可能对此提供了指导:

Using this approach you'll end up with a full AspNet application and a lightweight web app that integrated directly with desktop code. 使用这种方法,您将获得完整的AspNet应用程序和直接与桌面代码集成的轻量级Web应用程序。 You'll integrate those two as if you're integrating two web servers: using HTTP calls and more. 您将像集成两个Web服务器一样集成这两个服务器:使用HTTP调用等。

2 - Named pipes & TCP 2-命名管道和TCP

Named pipes are very interesting but you should carefully choose between them or TCP communication as each has it's own pros and cons. 命名管道非常有趣,但是您应该在它们之间进行选择,或者在TCP通讯之间进行选择,因为它们各有利弊。 You can find an example of Names Pipe / TCP here: https://github.com/jacqueskang/IpcServiceFramework 您可以在此处找到名称管道/ TCP的示例: https : //github.com/jacqueskang/IpcServiceFramework

For more information about named pipe x tcp pros and cons, I've found this post to be really useful: http://saurabhsinhainblogs.blogspot.com/2015/09/what-is-difference-between-tcp-ip-and-Named-Pipes.html 有关命名管道x tcp利弊的更多信息,我发现这篇文章非常有用: http : //saurabhsinhainblogs.blogspot.com/2015/09/what-is-difference-between-tcp-ip-and -Named-Pipes.html

3 - Message queues 3-消息队列

I's like a silver bullet. 我就像银弹。 A huge and heavy silver bullet but still, a silver bullet. 巨大而沉重的银色子弹,但仍然是银色子弹。 This works fine with, ell, pretty much any type of interprocess communication as you'll have a third player in charge of receiving and trasmitting messages and both players (server / client) will listen or publish to this queue. 在几乎任何类型的进程间通信中,这种方法都可以正常工作,因为您将由第三个参与者负责接收和发送消息,并且两个参与者(服务器/客户端)都将侦听或发布到此队列。 You can check NetMQ , RabbitMQ , MSMQ , RestBus , ActiveMQ , ZeroMQ or you can even build your own based on SQL Server for instance (although I'd not recommend that unless you're really sure of what you're doing). 您可以检查NetMQRabbitMQMSMQRestBusActiveMQZeroMQ,或者甚至可以基于SQL Server构建自己的数据库(尽管我不建议您这样做,除非您真的确定自己在做什么)。

4 - Others 4-其他

You have sockets, files (with automatic monitoring physical file system) and many other possible approaches to perform integration without user interaction. 您拥有套接字,文件(具有自动监视物理文件系统)和许多其他可能的方法,无需用户交互即可执行集成。 Even if I put here 20 other approaches, it would most likely miss one or two others. 即使我在这里使用其他20种方法,也很可能会错过另外一两种方法。 Just search for AspNet Core Interprocess Communication and you'll find plenty resources about that :) 只需搜索AspNet Core Interprocess Communication ,您将找到很多有关此的资源:)

Some other useful resources: 其他一些有用的资源:

This post has a reliable compilation of liks that will help on each IPC approach you might wish to test: https://weblogs.asp.net/ricardoperes/local-machine-interprocess-communication-with-net 这篇文章有可靠的liks汇编,将有助于您可能希望测试的每种IPC方法: https ://weblogs.asp.net/ricardoperes/local-machine-interprocess-communication-with-net

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM