I have an ASP.NET application built on NET 4.8 which includes SignalR client using Microsoft.AspNet.SignalR 2.4.3, and I need to call from JS into a SignalR server built using Microsoft.AspNetCore.SignalR 6.0.1
The server URL provided by server developer is https://api.myservice.com/signalR/main, and I need to call a method names JoinSession
The server developer told me to call without a hub, but I don't know how to do that from AspNet.SignalR 2.4.3. Or to try 'MainHub' as hub name which doesn't work.
I tried the following code
let connection = j$.hubConnection('https://api.myservice.com/signalR/main');
let hubProxy = connection.createHubProxy('MainHub');
//Start the connection
connection.start().done(function () {
// Call the server method
hubProxy.invoke('JoinSession', uID, "mySession").done(function () {
console.log('JoinSession successfully');
}).fail(function (error) {
console.error('Error invoking JoinSession: ' + error);
});
}).fail(function (error) {
console.error('Error starting connection: ' + error);
});
When I try this code I get the following error
GET https://api.myservice.com/signalR/main/signalr/negotiate?clientProtocol=2.1&connectionData=%5B%5D&_=1709211174237 404 (Not Found)
Error starting connection: Error: Error during negotiation request
Notice the additional signalr string added by the SignalR JS code at the end of my url
The server develop suggested me to try this
var connection = new signalR.HubConnectionBuilder()
.withUrl("https://api.myservice.com/signalR/main")
.build();
// Start the connection
connection.start().then(function () {
//...
})
But this doesn't work because there is no method HubConnectionBuilder in AspNet.SignalR 2.4.3
What should I do? How to call the 6.0.1 AspNetCore SignalR server from 2.4.3 AspNet SignalR client?
Some additional info The client app uses SignalR by itself too, between it's client part and the backend.
And the SignalR is configured at startup as below (to allow client size to interact with the backend directly
<Assembly: OwinStartup(GetType(SignalRConfig))>
Public Class SignalRConfig
Public Sub Configuration(app As IAppBuilder)
app.MapSignalR("/signalr", New Microsoft.AspNet.SignalR.HubConfiguration())
End Sub
End Class
Then from the local client I can access local SignalR server code as
// init SignalR MapAssetID client
let tmHub = null;
try {
tmHub = j$.connection.tmHub;
} catch (e) {
console.error('Cannot access SignalR tmHub')
}
And later I can use SignalR
if (tmHub) {
tmHub.client.updateMapAssetID = _updateMapAssetID;
j$.connection.hub.start();
}
This all works just fine
I suspect I might need to add some additional configuration to the SignalRConfig class to let the client interact properly with the remote AspNetCore server, but I don't know what and where to look.
Short answer, you cannot use them together. The CORE version was a rewrite. You can see more information here with this question.
SignalR version compatability (StatusCode: 405 'Method Not Allowed')