SignalR Chat App in WinForm With Remote Clients

2019-02-19 14:44发布

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.

标签: signalr
1条回答
做个烂人
2楼-- · 2019-02-19 15:39

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

查看更多
登录 后发表回答