[英]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. 我正在启动一个小代码项目以从过程中学习,但是我不确定在不同部分之间进行通信的最佳方法是什么。
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.