WPF SignalR server returns HTTP 400 Bad Request (invalid host address)

I'm trying to configure a SignalR hub to be able to send notifications to a bunch of WPF clients over the Internet. I tried to follow the basic principles and tutorials and created WPF SignalR Server (for testing purposes only). It was placed on a server on my local network, and it looks like this:

Startup.cs

class Startup
{
    public void Configuration(IAppBuilder app)
    {
        HubConfiguration hc = new HubConfiguration();
        hc.EnableDetailedErrors = true;

        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR(hc);
    }
}

MainWindow.xaml.cs

public IDisposable SignalR { get; set; }
const string ServerURI = "http://localhost:8554";

private void StartServer()
{
    try
    {
        SignalR = WebApp.Start(ServerURI);
    }
    catch (TargetInvocationException)
    {
        WriteToConsole("A server is already running at " + ServerURI);
        return;
    }
    this.Dispatcher.Invoke(() => btnStopHub.IsEnabled = true);
}

AdHocHub.cs

public class AdHocHub : Hub
{
    public void Send(string data)
    {
        Clients.All.notifyData(data);
    }

    public override Task OnConnected()
    {
        Application.Current.Dispatcher.Invoke(() => 
            ((MainWindow)Application.Current.MainWindow).WriteToConsole("Client connected: " + Context.ConnectionId));
        return base.OnConnected();
    }

    public Task OnDisconnected()
    {
        Application.Current.Dispatcher.Invoke(() =>
            ((MainWindow)Application.Current.MainWindow).WriteToConsole("Client disconnected: " + Context.ConnectionId));

        return base.OnDisconnected(true);
    }
}

The server starts just fine. However, when I try to connect a client to it, he refuses to give me 400 - Bad Request. If I try to go to http://192.nnn.nnn.nnn/signalr, all I get is Bad Request - Invalid Hostname. If I run the server and the client on the same computer, everything works as it should. What am I doing wrong here?

:

private async void ConnectAsync()
{
    Connection = new HubConnection(ServerURI);
    HubProxy = Connection.CreateHubProxy("AdHocHub");
    HubProxy.On<string>("notifyData", (notifyData) => this.Dispatcher.Invoke(() => txtEvents.AppendText(notifyData.ToString())));

    try
    {
        await Connection.Start();
    }
    catch (HttpRequestException ex)
    {
        MessageBox.Show(ex.ToString());
        lblStatus.Content = "Unable to connect to server: Start server before connecting clients.";
        return;
    }
    txtEvents.AppendText("Connected to server and listening...");
}

URI IP-, TargetInvocationException, .

, , , , CorsOptions AllowAll.

+4
1

( , , , )

ServerURI localhost http://+:8554, http://+:8554. , localhost.

, , , TargetInvocationException TargetInvocationException, UAC .

0

All Articles