ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,080 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I simply try to invoke a message and i get an error:
Unhandled Rejection (Error): An unexpected error occurred invoking 'SendMessageToGroup' on the server.
C# Hub:
public class ChatHub : Hub
{
public async Task SendAll(string message)
{
await Clients.All.SendAsync("ReceiveAllMessage", message);
}
public async Task JoinGroup(string group)
{
await Groups.AddToGroupAsync(Context.ConnectionId, group);
}
public async Task SendMessageToGroup(string group, string message)
{
string time = DateTime.Now.ToString();
await Clients.Groups(group).SendAsync("ReceiveMessage", message, time);
}
public override async Task OnConnectedAsync()
{
string userId = "user32";
await Clients.Caller.SendAsync("UserConnected", userId);
await base.OnConnectedAsync();
}
}
Client side: ReactJs:
const send = async () => {
console.log("send to group")
await Newconnection.invoke("SendMessageToGroup", cookies.Default, text)
await Newconnection.invoke("SendAll","3r2r");
const data = {
"message" : text,
"accesToken" : cookies.Default,
"isHelper" : false
}
const res = await axios.post('https://localhost:44332/api/LiveChat/Message',data)
if(res.status === 200)
console.log("succesful send message")
}