C
C#2y ago
skyslide22

✅ SignalR Blazor Wasm Not Reliable When Deployed

ay, i got a blazorwasm --hosted project, where we have build a chat app. the problem is, when deployed to azure, the chat is not working all the time, the messages are missing, randomly. also, we use a controller to inject messages, that one is also not working sometimes this is the controller we use
[ApiController]
[Route("[controller]/[action]")]
public class ApiController : TwilioController
{
private readonly IHubContext<ChatHub> _hubContext;

public ApiController(IHubContext<ChatHub> hubContext)
{
_hubContext = hubContext;
}


[HttpPost]
public async Task<bool> InsertSMSIntoChat(InsertSMSIntoChat_InputParams iparams)
{
try
{
await _hubContext.Clients.All.SendAsync(Messages.RECEIVE, iparams.PhoneNumber, iparams.Message);
Console.WriteLine("user "+ iparams.PhoneNumber + " wrote " + iparams.Message + " (API)");
return true;
}
catch(Exception e)
{
return false;

}

}
}
[ApiController]
[Route("[controller]/[action]")]
public class ApiController : TwilioController
{
private readonly IHubContext<ChatHub> _hubContext;

public ApiController(IHubContext<ChatHub> hubContext)
{
_hubContext = hubContext;
}


[HttpPost]
public async Task<bool> InsertSMSIntoChat(InsertSMSIntoChat_InputParams iparams)
{
try
{
await _hubContext.Clients.All.SendAsync(Messages.RECEIVE, iparams.PhoneNumber, iparams.Message);
Console.WriteLine("user "+ iparams.PhoneNumber + " wrote " + iparams.Message + " (API)");
return true;
}
catch(Exception e)
{
return false;

}

}
}
5 Replies
skyslide22
skyslide22OP2y ago
so, basically await _hubContext.Clients.All.SendAsync(Messages.RECEIVE, iparams.PhoneNumber, iparams.Message); is clearly not working 100%, more like 30%
JakenVeina
JakenVeina2y ago
I find that tough to believe, SignalR already includes its own protocols for message error detection and replaying and such as does TCP not that that's terribly helpful but I'll wager there some misuse of some kind in your own code like somehow you're not maintaining the connection properly if you really wanna screw around, you could try swapping to gRPC, as a proof-of-concept
skyslide22
skyslide22OP2y ago
it is actually the official documentations code from microsoft
skyslide22
skyslide22OP2y ago
SignalR HubContext
Learn how to use the ASP.NET Core SignalR HubContext service for sending notifications to clients from outside a hub.
skyslide22
skyslide22OP2y ago
we use horizontal scaled servers, that breaks it, my bad
Want results from more Discord servers?
Add your server