1
votes

I'm setting up a signalr connection from my angular front-end to a Asp.Net Core back-end. With fiddler i see multiple calls when starting the connection. The first call isn't completing which is a problem for our e2e tests.

I tried set SkipNegotiation: true, transport: SignalR.HttpTransportType.WebSockets but then the connection can't be established anymore because of a missing Connection ID

this.hubConnection = new signalR.HubConnectionBuilder()                          
        .configureLogging(signalR.LogLevel.Information)
        .withUrl('/api/notificationHub', { 
                  // skipNegotiation: true, transport: 
                     signalR.HttpTransportType.WebSockets
                 }).build();
this.hubConnection.start().then((x) => {
  console.log(x);
  }).catch((x) => {
  console.log(x);
});

I expect all calls to complete. but the actual situation is that the first call doesn't complete (or it takes a very long time)

enter image description here

GET http://localhost:4200/api/notificationHub?id=BHSyLOnn5BfBbaFYQ7qboQ 

--Raw request of first call

GET http://localhost:4200/api/notificationHub?id=cm1MjKA22om6orpWoDcO3Q HTTP/1.1 Host: localhost:4200 Connection: keep-alive Accept: text/event-stream Cache-Control: no-cache User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36 Sec-Fetch-Mode: cors Sec-Fetch-Site: same-origin Referer: http://localhost:4200/ Accept-Encoding: gzip, deflate, br Accept-Language: nl,en-US;q=0.9,en;q=0.8,nl-NL;q=0.7

--Raw request of second call

POST http://localhost:4200/api/notificationHub?id=BHSyLOnn5BfBbaFYQ7qboQ HTTP/1.1 Host: localhost:4200 Connection: keep-alive Content-Length: 32 Sec-Fetch-Mode: cors Origin: http://localhost:4200 X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36 Content-Type: text/plain;charset=UTF-8 Accept: / Sec-Fetch-Site: same-origin Referer: http://localhost:4200/ Accept-Encoding: gzip, deflate, br Accept-Language: nl,en-US;q=0.9,en;q=0.8,nl-NL;q=0.7

{"protocol":"json","version":1}

1
1st one might be the OPTION call and 2nd be the actual call.Iftifar Taz
It looks like you are right, but I still don't understand why it doesnt give a response or is that normal for OPTION calls?Revenger1986
Have a read here to more about OPTION callsIftifar Taz

1 Answers

1
votes

MY problem is solved. The first call was the handshake for the signalR connection. Which returned 101 switching protocol when running my front-end and back-end from visual studio. (Which uses ISS Express)

But when my back-end was hosted with ISS it didn't return 101. (It didn't return anything)

After turning on some extra logging on the signalR connection I found out that IIS Express was using websocket but that IIS didnt.

I had to install websockets in IIS to resolve my problem.

Thanks for the suggestions!