locked
Signal R hosted is not accesible from Client RRS feed

  • Question

  • User-137746281 posted

    Im using signal r v2 and created a web application project in the solution where I have a hub and starup

    Hub:

    public class CallHub : Hub
    {
    public void UpdateCallStatus(string ConnectionId, string callId, string callStatus)
    {
    Clients.Client(ConnectionId).callStatusMessage(callId, callStatus);
    }
    }

    Startup:

    public void Configuration(IAppBuilder app)
    {
    app.Map("/signalr", map =>
    {
    // Setup the cors middleware to run before SignalR.
    // By default this will allow all origins. You can
    // configure the set of origins and/or http verbs by
    // providing a cors options with a different policy.
    map.UseCors(CorsOptions.AllowAll);

    var hubConfiguration = new HubConfiguration
    {
    // You can enable JSONP by uncommenting line below.
    // JSONP requests are insecure but some older browsers (and some
    // versions of IE) require JSONP to work cross domain
    EnableJSONP = true,
    EnableDetailedErrors = true,
    EnableJavaScriptProxies = true
    };

    // Run the SignalR pipeline. We're not using MapSignalR
    // since this branch is already runs under the "/signalr"
    // path.
    map.RunSignalR(hubConfiguration);
    });

    }

    I also have a web application that I use as the client which simply has an index.html page and a js files that communicates with the signal r web appplication.

    The js File:

    (function () {
    var app = angular.module('call-app', []);

    app.config(function ($httpProvider) {
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
    });

    app.controller('CallContoller', function ($scope) {
    // scope variables
    var CntUnique = 0;
    //local Console App Signal R Hub
    var connection = $.hubConnection("http://ipaddress:2536/signalr", { useDeaultPath: false });
    var connectionId = null;
    $scope.CallHub = connection.createHubProxy('CallHub');

    connection.start().done(function () {
    alert('Connected');
    connectionId = connection.id;
    }).fail(function (reason) {
    alert("SignalR connection failed: " + reason);
    //console.log("SignalR connection failed: " + reason);
    });
    })
    }());

    These two projects are under one solution when I run it locally I am able to communicate with signal r and broadcast messages to the client. But when I publish and host the signalr web application to iis and try to use it fails to connect. The error I get is "Error during negotiations request". I researched issue and found out about Cross domain and being able to enablecrossdomain in the hubconfiguration but signalr v2 doesnt have that option. Can someone please help figure out how do I host the signal r app so I can communicate it from a client

    Thursday, March 16, 2017 3:24 PM

All replies

  • User-1838255255 posted

    Hi Arnold0121,

    Firstly, I’d like to know if your AngularJS client app and SignalR Hub are hosting on same IIS website.


    Secondly, to find and troubleshoot the issue, you could enable tracing and log on your hub.

    Best Regards,

    Eric Du

    Friday, March 17, 2017 6:17 AM
  • User-703012200 posted

    Please try to self host the Hub by console application.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.AspNet.SignalR;
    using Microsoft.AspNet.SignalR.Hubs;
    using Microsoft.AspNet.SignalR.Client;
    using Microsoft.Owin.Hosting;

    namespace SignalRHost
    {
    class Program
    {
    static void Main(string[] args)
    {

    string url = "http://localhost:8077";
    using (WebApp.Start(url))
    {
    Console.WriteLine("Server running on {0}", url);
    Console.ReadLine();
    }

    System.Console.Read();
    }
    }

    and here is my Hub.

    [HubName("MyHub")]
    public class MyHub:Hub
    {

    public string getdetails( string s)
    {
    return "Hi" + s;

    }

    }

    To enable SignalR in your Application, create a class called Startup with the code given below.

    [assembly: OwinStartup(typeof(SignalRHost.Startup))]

    namespace SignalRHost
    {
    public class Startup
    {
    public void Configuration(IAppBuilder app)
    {

    app.MapSignalR();

    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
    }
    }
    }

    Thursday, April 20, 2017 11:15 AM