I've created a .net core controller which, when using postman, I can hit the Get method successfully (validated with breakpoints on the controller constructor and get method) with the URL (https://localhost:44447/api/callsynchronisation/ws)
The code looks like this:
public class CallSynchronisationController : ApiControllerBase
{
private IWebSocketHandler handler;
public CallSynchronisationController(IWebSocketHandler handler)
{
this.handler = handler;
}
[HttpGet("ws")]
public async Task Get()
{
if (HttpContext.WebSockets.IsWebSocketRequest)
{
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
await handler.Handle(Guid.NewGuid(), webSocket);
}
else
{
HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
}
}
}
In my startup.cs I've added app.UseWebSockets(). This code does execute as expected.
I've set up websockets in angular with the adress wss://localhost:44447/api/callsynchronisation/ws.
When I try to send a message the connection is still in the connecting state
In chrome the initiating ws request never gets a response from the server. I see is the request with a header "upgrade" with the value websocket as expected.
The constructor for the controller does not execute (although it does for the previously mentioned https get request).
What am I doing wrong??