SignalR Chat App in WinForm With Remote Clients

早过忘川 提交于 2019-12-09 03:21:38

问题


i am new in signalR , i have tried and learn from different web sites like github and etc etc

But i couldn't find the solution for my problem.... and now i am getting confused...

My problem is:

I have developed a Chat app in Winform with Web Services and Centralized Database and it is working fine in different countries as in different branches of one organization.

But i want to convert that Chat App into SignalR to achieve more efficiency but i couldn't understand , how to do it in SignalR. because All tutorials of SignalR on Web in one Solution.

like Web , Console or WinRT communicated with each other but they are in one solution but in my scenerio i cannot put the service or Web Page in WinForm application.

Please please help me out in this manner.


回答1:


What you need to do is use the SignalR for .NET clients. Bring that into your project using NuGet assuming you are using Visual Studio.

You will need to import the following generally:

 using Microsoft.AspNet.SignalR.Client;
 using Microsoft.AspNet.SignalR.Client.Hubs;

Assuming you are following most of the tutorials on the web you can need the following to connect:

 public IHubProxy Proxy { get; set; }
 public HubConnection Connection { get; set; }

Also you will need to set the connection like so:

 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");

This part will need to be in an async function:

 //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();

More material fro the link below, this guy has it running on Console app, WPF app, and web clients so you can see the difference.

Standard tutorial on how to make the web server.

SIGNALR MESSAGING WITH CONSOLE SERVER AND CLIENT, WEB CLIENT, WPF CLIENT



来源:https://stackoverflow.com/questions/20476404/signalr-chat-app-in-winform-with-remote-clients

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!