azure - SignalR SelfHost: Issue on calling Signalr server from JavaScript Client -
i have self hosted signalr server referencing
"signalr owin simple example javascript client not being called" , "https://github.com/signalr/signalr/wiki/self-host"
links, when try call hub javascript got following error
"error: signalr: error loading hubs. ensure hubs reference correct, e.g. ."
my self hosted server that:
"hub class"
using microsoft.aspnet.signalr; using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using microsoft.owin.hosting; using owin; namespace signalrworker { public class chat:hub { public void send() { clients.all.send("hi"); } } }
"startup class"
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using microsoft.aspnet.signalr; using owin;
namespace signalrworker { public class startup { public void configuration(iappbuilder app) { // turn cross domain on var config = new hubconfiguration { enablecrossdomain = true ,enablejavascriptproxies=true,enabledetailederrors=true};
// map out http://localhost:8080/signalr default app.maphubs(config); } }}
"azure worker role"
using system; using system.collections.generic; using system.diagnostics; using system.linq; using system.net; using system.threading; using microsoft.windowsazure; using microsoft.windowsazure.diagnostics; using microsoft.windowsazure.serviceruntime; using microsoft.windowsazure.storage; using microsoft.aspnet.signalr; using owin; using microsoft.owin.hosting;
namespace signalrworker { public class workerrole : roleentrypoint { public override void run() { // sample worker implementation. replace logic. trace.traceinformation("signalrworker entry point called", "information"); try {
using (webapp.start<startup>("http://127.0.0.1:82/")) { trace.traceinformation("working", "server running @ http://127.0.0.1:82/"); } while (true) { thread.sleep(10000); trace.traceinformation("working", "information"); } } catch (exception ex) { thread.sleep(1000); trace.writeline("error", ex.message); } } public override bool onstart() { // set maximum number of concurrent connections servicepointmanager.defaultconnectionlimit = 12; // information on handling configuration changes // see msdn topic @ http://go.microsoft.com/fwlink/?linkid=166357. return base.onstart(); } }}
and aignalr client follows:
@viewbag.title - asp.net mvc application @styles.render("~/content/css") @* @scripts.render("~/bundles/modernizr")*@
</head> <body>     <header>         <div class="content-wrapper">             <div class="float-left">                 <p class="site-title">@html.actionlink("your logo here", "index", "home")</p>             </div>             <div class="float-right">                 <section id="login">                     @html.partial("_loginpartial")                 </section>                 <nav>                     <ul id="menu">                         <li>@html.actionlink("home", "index", "home")</li>                         <li>@html.actionlink("about", "about", "home")</li>                         <li>@html.actionlink("contact", "contact", "home")</li>                     </ul>                 </nav>             </div>         </div>     </header>     <div id="body">         @rendersection("featured", required: false)         <section class="content-wrapper main-content clear-fix">             @renderbody()         </section>     </div>     <footer>         <div class="content-wrapper">             <div class="float-left">                 <p>© @datetime.now.year - asp.net mvc application</p>             </div>         </div>     </footer>      @scripts.render("~/bundles/jquery")  <script src="~/scripts/jquery.signalr-1.1.2.js"></script>      <script type="text/javascript" src="http://127.0.0.1:82/signalr/hubs"></script>     <script type="text/javascript">         $(function () {              /* // proxy created on fly             var myhub = $.connection.chat;              // declare function on hub server can invoke             myhub.send = function (message) {                 console.log("hi");             };             */             // start connection             $.connection.hub.url = 'http://127.0.0.1:82/signalr';             $.connection.hub.start(function() {                 console.log("hi");             });           });     </script> </body> please possible due work got stuck
thanks in advance
 
 
Comments
Post a Comment