waywayway
waywayway

Reputation: 53

SignalR WPF Client can't reach hub deployed on IIS when IIS runs on a different system

I just play a little bit with signalR. My application has only one simple hub which is stored in an ASP.NET Application and I wrote a WPF client, which interacts via the hubconnection and the created proxy with the ASP.NET Application. Everything works fine on my local PC. I deployed the ASP.NET Application on IIS.

Now I am getting to the point...

When I type the following into my browser on my own PC (pcthi-and)

http://pcthi-and:8080/signalr/hubs

I'll get what I want

When I type the same url into a browser of another pc I'll get the same response and everything looks fine.

But my Application only works on my pc and not on the other one. When I start the hubconnection on the other pc I don't get a connectionId.

I tried to change the url to my IP-Address without effect.

Browser call to hub works but the Application doesn't work.

The call looks like this:

private bool tryToConnectToCoffeService()
    {
        try
        {
            this.hubConnection = new HubConnection(ConfigurationManager.ConnectionStrings["coffeeConnection"].ConnectionString);

            this.hubConnection.Credentials = CredentialCache.DefaultNetworkCredentials;

            this.coffeeService = this.hubConnection.CreateHubProxy("coffee");

            this.hubConnection.Start();

            if (string.IsNullOrEmpty(hubConnection.ConnectionId))
            {
                return false;
            }

            return true;
        }
        catch(Exception ex)
        {
            return false;
        }
    }

The Global.asax:

public class Global : System.Web.HttpApplication
{

    protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.MapHubs();
    }

The hub like this

[HubName("coffee")]
public class CoffeeHub : Hub
{

My Hub Connection String is this:

"http://pcthi-and:8080/"

Or:

"http://My-Current-IP-Address:8080/"

I use SignalR 1.0 rc2.

Does anyone have an idea? Thanks for helping.

Cheers

Frank

Upvotes: 4

Views: 1341

Answers (1)

halter73
halter73

Reputation: 15244

I think you need to change

hubConnection.Start();

to

hubConnection.Start().Wait();

If you are running .NET 4.5 you could make the tryToConnectToCoffeService method async and then await when you start the hub connection.

await hubConnection.Start();

It likely works today on localhost because the client can finish connecting before if (string.IsNullOrEmpty(hubConnection.ConnectionId)) executes.

It is probably taking longer to connect from another machine which exposes the race condition present when you don't wait for HubConnection.Start() to complete.

Upvotes: 1

Related Questions