I created a sample SignalR project (I am not talking about ABP or Module Zero Here). Normal ASP.Net Core Application.
My startup class has following code.
app.Map("/signalr", map => { map.UseCors(CorsOptions.AllowAll); var hubConfiguration = new HubConfiguration{}; map.RunSignalR(hubConfiguration); });
Now there is another application (say windows application) who wanted to connect to my application using signalR. So the windows application use the following code to connect to my Hub hubConnection = new HubConnection("http://localhost:18444/signalr/hubs");
Please see the URL of Hub in the above code. When I browse the above URL (<a class="postlink" href="http://localhost:18444/signalr/hubs">http://localhost:18444/signalr/hubs</a>), it gives me following output...
/*!
*/
/// <reference path="....\SignalR.Client.JS\Scripts\jquery-1.6.4.js" /> /// <reference path="jquery.signalR.js" /> (function ($, window, undefined) { /// <param name="$" type="jQuery" /> "use strict";
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
}
var signalR = $.signalR;
function makeProxyCallback(hub, callback) {
return function () {
// Call the client hub method
callback.apply(hub, $.makeArray(arguments));
};
}
function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;
for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];
if (!(hub.hubName)) {
// Not a client hub
continue;
}
if (shouldSubscribe) {
// We want to subscribe to the hub events
subscriptionMethod = hub.on;
} else {
// We want to unsubscribe from the hub events
subscriptionMethod = hub.off;
}
// Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];
if (!$.isFunction(memberValue)) {
// Not a client hub function
continue;
}
subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue));
}
}
}
}
}
$.hubConnection.prototype.createHubProxies = function () {
var proxies = {};
this.starting(function () {
// Register the hub proxies as subscribed
// (instance, shouldSubscribe)
registerHubProxies(proxies, true);
this._registerSubscribedHubs();
}).disconnected(function () {
// Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs.
// (instance, shouldSubscribe)
registerHubProxies(proxies, false);
});
proxies['myHub'] = this.createHubProxy('myHub');
proxies['myHub'].client = { };
proxies['myHub'].server = {
broadCastToAllClients: function (whomToSend) {
return proxies['myHub'].invoke.apply(proxies['myHub'], $.merge(["BroadCastToAllClients"], $.makeArray(arguments)));
},
connect: function (User) {
return proxies['myHub'].invoke.apply(proxies['myHub'], $.merge(["Connect"], $.makeArray(arguments)));
},
sendToServer: function (msg) {
return proxies['myHub'].invoke.apply(proxies['myHub'], $.merge(["SendToServer"], $.makeArray(arguments)));
}
};
return proxies;
};
signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false });
$.extend(signalR, signalR.hub.createHubProxies());
}(window.jQuery, window));
Question is What would be my hub URL in Module Zero project. My startup class has following code: app.UseSignalR(routes => { //routes.MapHub<AbpCommonHub>("/signalr"); routes.MapHub<iVend365Hub>("/signalr"); });
Appreciate your response.
Regards, Mahendra
could you please provide me a sample application that uses signalR to send and receive message from Client and Vice-versa....
Thanks...I did that...Now following the document <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/SignalR-AspNetCore-Integration">https://aspnetboilerplate.com/Pages/Doc ... ntegration</a> at the following step..."Client-Side (jQuery)", I included below lines in my Area/Mpa/Views/Layout/_Layout.cshtml file....
<script src="~/lib/signalr-client/signalr.min.js"></script> <script src="~/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.signalr-client.js"></script>
Now when I run any of my pages, it throws me following error:
abp.signalr-client.js:97 Uncaught TypeError: Cannot read property 'WebSockets' of undefined at startConnection (abp.signalr-client.js:97) at Object.abp.signalr.connect (abp.signalr-client.js:47) at abp.signalr-client.js:107 at abp.signalr-client.js:110
Please help...
Is Abp.Owin 3.6.1 supports .NetCore 2.0 yet?
Because when I add the Package ABP.Owin, it restored using .Net Framework 4.6.1?
Agree what you are saying....
but is there any alternate, so I will save my lots of time to refactor the code as per your suggestion....
Regards, Mahendra
Hi Aaron,
I got stuck again.... I have Linq Query, that returns me an anonymous entity. Now, when I try to map the above anonymous entity to one of my DTO (of course my anonymous entity does not have all the properties that the DTO has), I have to write following code before mapping it to my DTO.
Mapper.Initialize(cfg => cfg.CreateMissingTypeMaps = true);
Now this code is throwing following error..
Mapper already initialized. You must call Initialize once per application domain/process.
I tried commenting this code
//Mapper.Initialize(cfg => cfg.CreateMissingTypeMaps = true);
and instead tried writing the following code in CustomDtoMapper.cs configuration.CreateMissingTypeMaps = true;
But still the Automapper is throwing error of missing map while mapping the anonymous entity to DTO...
Please advise....
Thanks...Much appreciated....
Regards, Mahendra
Thanks aaron....it worked....Many thanks for the solution....
Can you please just clarify one more thing to me....
So now I am on ASPNetZero 4.5 with ABP 3.6.1...... My question is if I do not upgrade to ASPNetZero to 5.4, Can I still use SignalR....
Regards, Mahendra
As I said, I have not changed anything except updating the ABP Nuget from 3.0.0 to 3.6.1 and also updated the other nugets to the latest version.
Now I have two solutions, One with ASPNetZero 4.5 having ABP 3.0.0 and Other with ASPNetZero still 4.5 but ABP 3.6.1 (Because I only updated the ABP nugets.)
And the reason to upgrade the ABP nuget is, I want to implement SignalR which is only supported on ABP >=3.6.0
In the old solution its running absolutely fine, but in the new it is throwing error.... I am really stuck..... Please help....
Hi,
I did not understand you completely. Exactly in which file I need to add the missing mapping. Also When In old version (ABP 3.0) it is working, why after updating the ABP nuget to 3.6.1 it stopped working....
Regards, Mahendra