Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to send data from server to client(my console application)wich have a connection to my "LocationHub". I tried to do as described in example from a link but got no result.

What I have tried:

Client Side Code is:
-------------------------
C#
public class Provider
{
static void Main(string[] args)
{
var connection = new HubConnection("http://192.168.1.88:8044/");
var myHub = connection.CreateHubProxy("LocationHub");

//This line it displaying Exception thrown: 'System.AggregateException' in mscorlib.dll
JavaScript
connection.Start().Wait();
myHub.On("addMessage", myString =>
{
Console.WriteLine("This is client getting messages from server :{0}", myString);
});
myHub.Invoke("Chatter", System.DateTime.Now.ToString()).Wait();
Console.Read();
}
}


Server side code is:
-----------------------
C#
class Program
{
static void Main(string[] args)
{
string url = "http://192.168.1.88:8044/";
using (WebApp.Start(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
IHubContext context = GlobalHost.ConnectionManager.GetHubContext();
for (int i = 0; i < 100; i++)
{
System.Threading.Thread.Sleep(3000);
context.Clients.All.addMessage("Current integer value : " + i.ToString());
}
Console.ReadLine();
}
}
}
[HubName("LocationHub")]
public class LocationHub : Hub
{
public void Send(string platform, string message)
{
Clients.All.messageReceived(platform, message);
}
}
}
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}


Error:
Exception thrown: 'System.AggregateException' in mscorlib.dll
Additional information: One or more errors occurred.

Inner Exception is:
{"StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:\r\n{\r\n Cache-Control: private\r\n Date: Tue, 20 Dec 2016 09:09:06 GMT\r\n Server: Microsoft-IIS/10.0\r\n X-Powered-By: ASP.NET\r\n Content-Length: 4938\r\n Content-Type: text/html; charset=utf-8\r\n}"}



What is the best solution for implementing this...??
How to solve??
Posted
v5

1 solution

In your client code, you're trying to call a method called "Chatter". But in your server code, the method is called "Send".

Also, your client is listening for a notification called "addMessage", but your server is sending a notification called "messageReceived".

ASP.NET SignalR Hubs API Guide - .NET Client (C#) | The ASP.NET Site[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900