我是signalR的新手,我曾尝试和学习github等不同的网站
但是我找不到解决问题的方法....现在我感到很困惑......
我的问题是:
我已经在Winform中使用Web服务和集中式数据库开发了一个聊天应用程序,它在不同的国家和一个组织的不同分支机构中运行良好.
但我想将Chat App转换为SignalR以实现更高的效率,但我无法理解,如何在SignalR中实现.因为在一个解决方案中Web上的SignalR的所有教程.
像Web,Console或WinRT相互通信,但它们在一个解决方案中,但在我的scenerio我不能把服务或网页放在WinForm应用程序中.
请以这种方式帮助我.
您需要做的是使用SignalR for .NET客户端.假设您使用的是Visual Studio,请使用NuGet将其带入您的项目中.
您通常需要导入以下内容:
using Microsoft.AspNet.SignalR.Client;
using Microsoft.AspNet.SignalR.Client.Hubs;
Run Code Online (Sandbox Code Playgroud)
假设您正在关注Web上的大部分教程,您可以通过以下方式进行连接:
public IHubProxy Proxy { get; set; }
public HubConnection Connection { get; set; }
Run Code Online (Sandbox Code Playgroud)
您还需要像这样设置连接:
public string Host = "http://YourSignalRChatAppLocationOnAzureOrLocally.cloudapp.net/";
Connection = new HubConnection(Host);
//Assuming your SignalR hub is also called ChatHub (If you followed most tutorials it will be)
Proxy = Connection.CreateHubProxy("ChatHub");
Run Code Online (Sandbox Code Playgroud)
这部分需要在异步函数中:
//If you are passing an object back and fourth otherwise String is fine
Proxy.On<ChatMessage>("Send", hello => OnSendData("Recieved send " + hello.Username + " " + hello.Content));
await Connection.Start();
Run Code Online (Sandbox Code Playgroud)
更多来自以下链接的资料,这个人在控制台应用程序,WPF应用程序和Web客户端上运行它,以便您可以看到差异.
与CONSOLE服务器和客户端,WEB客户端,WPF客户端的SIGNALR消息
| 归档时间: |
|
| 查看次数: |
8742 次 |
| 最近记录: |