简体   繁体   English

从API更新应用程序的正确方法是什么?

[英]What is the proper way to update an application from an API?

Project: 项目:

I have a project I want to do that involves an Arduino that sends serial data to a Raspberry Pi, And the Raspberry Pi displays the data to a screen and updates an API. 我有一个我想做的项目,涉及一个将串行数据发送到Raspberry Pi的Arduino,Raspberry Pi将数据显示到屏幕上并更新API。 I want a desktop application that also displays the data that was sent to the API. 我想要一个桌面应用程序,该应用程序还显示发送到API的数据。 To get a feel for the technologies, initially the only data sent is going to be a the state of a stopwatch timer that runs on the Raspberry Pi, IE running vs stopped. 为了对这些技术有所了解,最初发送的唯一数据将是在Raspberry Pi上运行的秒表计时器的状态,即IE运行与停止。 I know it would be simple to hit the API periodically from the application to retrieve new data, But I want the application to be updated when the API receives new information. 我知道定期从应用程序访问API以检索新数据会很简单,但是我希望在API收到新信息时对应用程序进行更新。 I was thinking some sort of a subscriber system where the applications I want updated can subscribe to the API and will be updated all at the same time. 我在考虑某种订户系统,我想要更新的应用程序可以订阅API,并且将同时全部更新。

Languages and Frameworks: 语言和框架:

The API will be written in dot net core 2.2. 该API将以点网核心2.2编写。 The desktop application will be written using WPF in dot net framework 4.7.2. 桌面应用程序将在点网框架4.7.2中使用WPF编写。 Other languages or frameworks used for the Arduino or Raspberry Pi are not relevant. 用于Arduino或Raspberry Pi的其他语言或框架不相关。

Question: 题:

How do I push data from an dot net core API to a WPF application whenever new data is pushed to the API? 每当有新数据推送到API时,如何将数据从点网核心API推送到WPF应用程序? Is this a good way to go about it? 这是个好方法吗? Any information, suggestions, Or relevant technologies/frameworks/native C# tools used for this purpose would be greatly appreciated. 任何用于此目的的信息,建议或相关技术/框架/本机C#工具将不胜感激。

It looks like you need Web Sockets. 看起来您需要Web套接字。

Web Sockets, as apposed to HTTP, create a persistent connection between the client and host, allowing the host to push data to the client in real time. 与HTTP相对应的Web套接字在客户端和主机之间创建持久连接,从而使主机可以将数据实时推送到客户端。

I recommend SignalR as an easy to use Web Socket framework, it can be easily added to a .NET Core app. 我建议SignalR作为易于使用的Web Socket框架,可以将其轻松添加到.NET Core应用程序中。

A great example of SignalR can be found on the Microsoft EShopOnContainers repo in the Ordering System. 可以在订购系统中的Microsoft EShopOnContainers存储库中找到SignalR的一个很好的示例。

The use a message queue between the main API and the SignalrHub, however you could easily combine the two for a simple application. 在主API和SignalrHub之间使用消息队列,但是,您可以轻松地将两者结合起来以构成一个简单的应用程序。

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

相关问题 从WindowsFormsApplicationBase.OnCreateMainForm()退出应用程序的正确方法是什么? - What's the proper way to exit the application from WindowsFormsApplicationBase.OnCreateMainForm()? 在EF 6中更新子实体的正确方法是什么? - What is the proper way to update child entities in EF 6? 确定应用程序位置的正确方法是什么? - What is the proper way to determine an application's location? 使用 OneDrive API 的正确方法是什么? - What is the proper way to work with the OneDrive API? 从 static void Main() 入口点退出 WinForms 应用程序的正确方法是什么 - What is the proper way to exit a WinForms application from static void Main() entry point 使用Windows API从Rich Text控件检索文本的正确方法是什么? - what's the proper way to retrieve text from a Rich Text Control using the Windows API? 用颜色创建画笔的正确方法是什么? - What is the proper way to create a brush from a color? 从BlockingCollection中获取项目的正确方法是什么? - What is the proper way to take an item from a BlockingCollection? 从浮点数获取整数的正确方法是什么? - What is the proper way to get an int from a float? 在Web API中的补丁操作中更新mongo的正确方法 - Proper way to update mongo in patch action in web api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM