Here is my complete code of SignalR. The question is when JavaScript client runs, it does not hit the breakpoint at QueryStringTokenResolver function of AuthConfigurer class.
I am sure, I must be missing something. Please advise....
----------------------------Application Service iVend365ApplicationModule.cs---------------------------- [DependsOn( typeof(iVend365CoreModule), typeof(AbpAspNetCoreSignalRModule) )] public class iVend365ApplicationModule : AbpModule { …… …... } ----------------------------Application Service iVend365Hub.cs---------------------------- public override Task OnConnectedAsync() { return base.OnConnectedAsync(); }
public override Task OnDisconnectedAsync(Exception exception)
{
ConnectedClient DisConnectedClient = AppStatic.ConnectedClients.Where(p => p.ConnectionId == Context.ConnectionId).SingleOrDefault();
AppStatic.ConnectedClients.Remove(DisConnectedClient);
Clients.All.SendAsync("PrintConnectedPOS", "POS - " + DisConnectedClient.POSKey + " DisConnected");
return base.OnDisconnectedAsync(exception);
}
public void RegisterPOS(Int32 TenantId, string POSKey)
{
ConnectedClient connectedClient = new ConnectedClient() { TenantId = TenantId, POSKey = POSKey, ConnectionId = Context.ConnectionId };
AppStatic.ConnectedClients.Add(connectedClient);
Clients.All.SendAsync("PrintConnectedPOS", "POS - " + POSKey + " Connected");
}
----------------------------MVC Web Startup.cs---------------------------- public IServiceProvider ConfigureServices(IServiceCollection services) { ……. services.AddCors(options => options.AddPolicy("CorsPolicy", builder => { builder .AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin() .AllowCredentials(); }));
services.AddSignalR(options =>
{
options.KeepAliveInterval = TimeSpan.FromSeconds(15);
});
…………….
…………….
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ………… app.UseCors("CorsPolicy");
app.UseSignalR(routes =>
{
routes.MapHub<iVend365Hub>("/signalr");
});
………………
…………..
}
-----------------MVC Web AuthConfigurer.cs---------------------------- private static Task QueryStringTokenResolver(MessageReceivedContext context) { if (!context.HttpContext.Request.Path.HasValue || !context.HttpContext.Request.Path.Value.StartsWith("/signalr")) { //We are just looking for signalr clients return Task.CompletedTask; }
var qsAuthToken = context.HttpContext.Request.Query["enc_auth_token"].FirstOrDefault();
if (qsAuthToken == null)
{
//Cookie value does not matches to querystring value
return Task.CompletedTask;
}
//Set auth token from cookie
context.Token = SimpleStringCipher.Instance.Decrypt(qsAuthToken, AppConsts.DefaultPassPhrase);
return Task.CompletedTask;
}
----------------------JavaScript Client (Another Project)-------------------- <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <script src="Scripts/signalr.js"></script> <script> const connection = new signalR.HubConnectionBuilder() //.withUrl("http://ivend365retail-signalrtest.azurewebsites.net/signalr?enc_auth_token=ABCD") .withUrl("http://localhost:62114/signalr") .configureLogging(signalR.LogLevel.Information) .build();
connection.start().then(function () {
connection.send("RegisterPOS", 1018, "418307399342882834");
//connection.send("RegisterPOS", 972, "441464738128330770");
});
connection.on("GetDeltaQueue", function (message) {
console.log(message);
});
connection.on("PrintConnectedPOS", function (message) {
console.log(message);
});
</script>
</body> </html>
Hi,
The link you shared is not opening and throwing 404 error.
Also, last time you provided me a ABP GitHub path to download signalr.min.js file.
since we have upgraded the ABP to 3.6.2. I am sure the above file (signalr.min.js) also must have got changed.
Could you please provide me the path from where I can download this file.....
I got the answer.... For the benefit of other people...if you are facing the same issue then please follow this URL....
<a class="postlink" href="https://docs.microsoft.com/en-us/aspnet/core/signalr/publish-to-azure-web-app?view=aspnetcore-2.1">https://docs.microsoft.com/en-us/aspnet ... etcore-2.1</a>
Hi Aaron,
Finally I got my mistake...The ABP 3.6.1 is using SignalR Preview1 and My Console App was using signalR RC1 and thats why my console app was not connecting the the server. The moment I took SignalR Preview1 (As suggested by you), it starts connecting the server..
Thanks again for your help....
Regards, Mahendra
Hi Aaron,
If my client application is WEB then it is successfully connect to my SignalR Server. Here is the Code of client
<script src="Scripts/jquery-1.6.4.js"></script> <script src="Scripts/jquery.signalR-2.2.2.js"></script>
<script src="http://localhost:62114/lib/signalr-client/signalr.min.js"></script>
<script>
debugger;
var connection = new signalR.HubConnection('http://localhost:62114/signalr', { transport: signalR.TransportType.WebSockets });
connection.start();
connection.on("getMessage", function (message) {
alert(message);
});
</script>
But if my client application is .Net Core Console application, I am unable to connect. Here is my code. var hubConnection = new HubConnectionBuilder() .WithUrl("http://localhost:62114/signalr", HttpTransportType.WebSockets) .Build();
hubConnection.On<string>("getMessage", (message) => Console.WriteLine(message));
hubConnection.StartAsync().Wait();
The error it says is Unable to connect to the server with any of the available transports...
I am using
What is wrong here? Please advise...
Do you recommend try using Microsoft.AspNetCore.SignalR.Client 1.0.0-preview1-28189
I am using following nuget in Windows App.
Microsoft.AspNet.SignalR.Client 2.2.2
Using your suggestion....I am able to successfully connect my client application with Server Application and also receive the message from server....Thanks for this...
But if my client application is a classic windows desktop application (instead of web application), then I am unable to connect to the server...
See the code below
HubConnection hubConnection; IHubProxy hubProxy;
hubConnection = new HubConnection("http://localhost:62114/signalr"); hubProxy = hubConnection.CreateHubProxy("iVend365Hub"); hubProxy.On<string>("getMessage", (message) => MessageBox.Show(message)); hubConnection.Start().Wait();
In the last line of above code "hubConnection.Start().Wait();", it throws the following error..
System.AggregateException occurred HResult=0x80131500 Message=One or more errors occurred. Source=mscorlib StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at WinFormsApp1.Form1..ctor() in D:\MNJ\R&D\SignalRDemo\WinFormsApp1\Form1.cs:line 25 at WinFormsApp1.Program.Main() in D:\MNJ\R&D\SignalRDemo\WinFormsApp1\Program.cs:line 19
Inner Exception 1: JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 2, position 1.
What am I missing...Please advise..
Regards, Mahendra
When I browse <a class="postlink" href="http://localhost:62114/signalr">http://localhost:62114/signalr</a> it gives me the following response... Connection ID required