来自 Windows Phone 8 的 SignalR 集线器连接 [英] SignalR Hub connectivity from Windows Phone 8

查看:30
本文介绍了来自 Windows Phone 8 的 SignalR 集线器连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试的应该是基本的;但一定是遗漏了什么.在本地运行的 MVC3 应用程序中定义了几个 SignalR 集线器.同样的解决方案有一个 Windows Phone 8 &一个 Windows 应用商店应用,两者都与 SignalR 集线器进行实时通信.SignalR 服务器使用最新的位 &客户使用最新的 .NET nuget.

What I'm trying should be basic; but must be missing something. Have couple of SignalR Hubs defined inside an MVC3 app running locally. Same solution has a Windows Phone 8 & a Windows Store app, both talking to the SignalR hubs for real-time communication. SignalR server uses latest bits & clients use latest .NET nuget.

在客户端,这是我习惯写的:

On the client side, this is what I'm used to writing:

        IHubProxy SignalRChatHub;
        HubConnection chatConnection = new HubConnection("http://localhost:53478/");
        SignalRChatHub = chatConnection.CreateHubProxy("ChatHub");

        await chatConnection.Start();
        if (chatConnection.State == Microsoft.AspNet.SignalR.Client.ConnectionState.Connected)
        {
           // Stuff here.
        }

这与 Windows 8 应用程序客户端和 Windows 8 应用程序客户端完美配合.我们可以轻松连接在 IIS 上本地运行的 SignalR 集线器.但是,相同的代码不适用于 Windows Phone 客户端.connection.start() 抛出 404 异常.

This works perfectly fine with a Windows 8 app client & we have easy connectivity with the SignalR hub running locally on IIS. However, the same code does not work for a Windows Phone client. The connection.start() bombs out with a 404 exception.

经过一些研究,看起来 WP Emulator VM 被视为不同的机器,并且虚拟地使用主机的网络.因此,IIS 可能会阻止来自外部的呼叫,不允许从 Windows Phone 8 应用程序访问 SignalR 集线器.因此,我调整了 SignalR 服务器应用程序的 applicationhost.config 以允许来自外部本地主机的连接.所以现在,SignalR 集线器既可以在本地主机上运行,​​也可以在本地 IP 之外运行.此外,路由已更改为允许 Global.asax.cs 中的跨域 SignalR 连接:

After a little research, it looks like the WP Emulator VM is treated as a different machine and uses the host machine's network virtually. So, IIS may be blocking calls from outside not allowing reach into the SignalR hub from Windows Phone 8 app. Accordingly, I tweak applicationhost.config for the SignalR server app to allow connectivity from outside localhost. So now, the SignalR hub is functional from both localhost and also off the local IP. Also, the routing has been changed to allow cross-domain SignalR connectivity in Global.asax.cs:

RouteTable.Routes.MapHubs(new HubConfiguration() { EnableCrossDomain = true });

Windows Phone 客户端代码更改为:

The Windows Phone client code is changed to:

HubConnection chatConnection = new HubConnection("http://<LocalIP>:53478/");

但这会继续使 connection.start() 失败,并出现远程服务器返回错误:未找到"异常.我让 Fiddler 嗅探来自电话模拟器的网络流量,但对 connection.start() 调用完全没有任何响应.

But this continues to fail the connection.start() with a "Remote server returned an error: Not Found" exception. I have Fiddler sniffing network traffic from the phone emulator and shows absolutely nothing in response to the connection.start() call.

我错过了什么?任何指针都会有所帮助..谢谢!

What am I missing? Any pointers would be helpful .. thanks!

推荐答案

自己想出来的.原来 WPDev 模拟器的 SignalR 连接问题实际上是由于 IIS/Windows 安全造成的.更多的 IIS 配置 &通过 Windows 防火墙打开本地端口修复了该问题.会写博客;但这两个帖子有帮助:

Figured it out myself. Turns out the SignalR connectivity issue from the WPDev emulator was actually due to IIS/Windows security. Little more IIS config & opening local ports through Windows Firewall fixed the problem. Will blog about it; but these two posts helped:

这篇关于来自 Windows Phone 8 的 SignalR 集线器连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆