I had a similar problem that strangely occurred on some computers: the first try fails and the second try works.
Never found the cause but "solved" it by adding a retry.
It also baffles me that there is so little information about these sort of Signal problems on the internet.
You might be interested in:
Diagnostics Guide · aspnet/SignalR Wiki · GitHub[
^]
Here is some code to give you an idea how the retry mechanism works, it is not a full example as I can not disclose the unencryption routines used:
private IHubProxy HubProxy { get; set; }
private int signalRretries;
this.signalRretries = 0;
this.SendXmlRequest();
SendXmlRequest()
{
if (this.hubConnection == null || this.hubConnection.State == ConnectionState.Disconnected)
{
Connect(30000, SignalrServerUri);
}
if (this.hubConnection.State != ConnectionState.Connected)
{
this.ShowError("Connection to SignalR server failed !");
this.Cursor = Cursors.Default;
}
else
{
HubProxy.Invoke("Send", UserName, requestEncrypt);
}
}
private bool Connect(int timeoutMs, string serverUri)
{
this.hubConnection = new HubConnection(serverUri);
this.hubConnection.Closed += Connection_Closed;
this.HubProxy = hubConnection.CreateHubProxy("SignalrHub");
this.HubProxy.On<string, string>("AddMessage", this.AddMessageReceived);
this.hubConnection.Start().Wait(timeoutMs);
}
private void AddMessageReceived(string name, string xmlEncryptedReply)
{
if (this.InvokeRequired)
{
this.Invoke(new Action(() => AddMessageReceived(name, xmlEncryptedReply)));
}
else
{
this.hubConnection.Closed -= Connection_Closed;
this.hubConnection.Stop();
var message = this.ProcessXmlReply(license, xmlEncryptedReply);
if (string.IsNullOrEmpty(message) || message.Equals(@"Reply is not valid"))
{
signalRretries++;
if (signalRretries < 3)
{
this.SendXmlRequest();
}
}
}
}