简体   繁体   English

从Web-> Web api->控制台应用程序进行通讯并再次返回的最佳方法是什么?

[英]What is the best way of communicating from web->web api->console app and back again?

I'm starting up a little code project to learn from the process, but I am not sure what's the best way of communicating between the different parts. 我正在启动一个小代码项目以从过程中学习,但是我不确定在不同部分之间进行通信的最佳方法是什么。

  • First, I have a pure html/js client where the users need to get live updates frequently. 首先,我有一个纯html / js客户端,用户需要经常获取实时更新。
  • Secondly, I'm considering having a web api application running to provide data. 其次,我正在考虑运行一个Web api应用程序以提供数据。
  • Thirdly I have a console application running, that needs to communicate with the web api application. 第三,我有一个正在运行的控制台应用程序,需要与Web api应用程序进行通信。

So I'm thinking about using WebSockets all the way from client->web api->console app, but I have trouble making it work. 因此,我正在考虑从客户端-> Web api->控制台应用程序一直使用WebSockets,但是我很难使它正常工作。 I can make the console app work as a server, but I can't figure out how to make the web api work as a client, so that when it spins up, creates a connection to the console app, and keeps it open for communication, while it delivers data to the clients upon requests. 我可以使控制台应用程序作为服务器工作,但是我不知道如何使Web api作为客户端工作,因此当它启动时,会创建与控制台应用程序的连接,并保持打开状态以进行通信,同时根据请求将数据传递给客户端。

I tried with different implementations and I have ended up with SignalR, as it seems like that's what people use today :) 我尝试了不同的实现,但最终使用了SignalR,因为今天人们似乎正在使用它:)

Since I have all these problems getting a connection I am wondering if there are better ways of sending data that fulfills my requirements? 由于我在连接时遇到了所有这些问题,所以我想知道是否有更好的方式发送满足我要求的数据? If WebSocket (using SignalR) is the way to go, can you provide some links with working examples? 如果要使用WebSocket(使用SignalR),是否可以提供一些带有实际示例的链接? I have tried all the top links from Google with no success ^^ 我尝试了Google的所有重要链接,但都没有成功^^

Thanks in advance 提前致谢

Your WebAPI project can act as WebSocket server as well. 您的WebAPI项目也可以充当WebSocket服务器。 Check this link that uses an IHttpHandler , but you can also do it in a WebAIP's controller how is explained here : Using WebSockets with ASP.NET Web API 检查使用IHttpHandler 此链接 ,但您也可以在WebAIP的控制器中执行此操作,方法如下: 将WebSockets与ASP.NET Web API一起使用

The console application should connect as client, using for example ClientWebSocket class . 控制台应用程序应使用例如ClientWebSocket class作为客户端连接。

WebSockets are persistent full duplex connections, so once the client is connected both ends can push information to the other end. WebSocket是持久的全双工连接,因此一旦客户端连接,两端就可以将信息推送到另一端。

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

相关问题 版本WCF Web API的最佳方法是什么? - What is the best way to version a WCF Web API? 在网络和桌面应用之间进行通信的好方法 - Good way of communicating between web and desktop app 在多形式环境中与Web服务通信的最佳方法 - Best way of communicating with web service in multi-form environment C#控制台应用程序最佳实践,用于一遍又一遍地ping Web API,直到返回特定值为止 - C# console application best practice for pinging a web API over and over again until a specific value is returned 来自控制台应用程序或Android应用程序的Https Web API - Https Web API from console app or android app 在Web API Razor中处理视图路由的最佳方法是什么 - What is the best way to handle the view routing in Web API Razor 从Web api上的同一端点正确使用两个“成功”响应之一的最佳方法是什么? - What's the best way to properly consume one of two “successful” responses from the same endpoint on a web api? 使用我的API中的访问令牌对C#MVC Web应用程序进行身份验证的最佳方法 - Best way to authenticate a C# MVC web app using an access token from my API 在Windows和Web App中处理数据库升级的最佳方法是什么? - What's the best way to process database upgrades in Windows and Web App? 读取/解析WEB API 2 IHttpActionResult响应的最佳方法是什么? - What is the best way of reading/parsing WEB API 2 IHttpActionResult responses?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM