Xamarin.iOS 上的 SignalR - 随机无法调用集线器方法 [英] SignalR on Xamarin.iOS - randomly not able to call Hub method

查看:40
本文介绍了Xamarin.iOS 上的 SignalR - 随机无法调用集线器方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 Hub 在 Azure 中运行,我在 Windows 中的控制台应用程序中完美运行.

I have a simple Hub running in Azure, that I have working perfectly from a console app in Windows.

我刚刚构建了一个简单的 Xamarin.iOS 测试应用,它出现了一些奇怪的行为.

I just built a simple test Xamarin.iOS app, and it is giving some strange behavior.

  1. 随机在 LTE/Wifi 或模拟器/设备上 - 调用集线器方法失败,调用集线器方法 X 时出错
  2. 随机大约 50% - 一切正常,就像 Windows 上的控制台应用程序一样 - 两者甚至互相发送消息

我在 iPhone 5S 和 iPhone 4S 的设备上对此进行了测试.

I tested this on an iPhone 5S and iPhone 4S for devices.

关于为什么会发生这种情况的任何想法?我在 2.0.0 版上使用便携式 NuGet 包.

Any ideas on why this would happen? I'm using the Portable NuGet package on version 2.0.0.

更新:

这是我启用跟踪时得到的结果(我清空了我的域):

Here is what I get when I enable tracing (I blanked out my domain):

2013-11-25 07:47:48.204 MyApp[5163:80b] 13:47:48.1865420 - null - ChangeState(Disconnected, Connecting)
2013-11-25 07:47:49.025 MyApp[5163:6b03] 13:47:49.0247930 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: GET http://mydomain.cloudapp.net/signalr/connect?transport=serverSentEvents&connectionToken=pVF6LN7KBOem7Ng2hrhx6dSByFe%2BxCr4u6RlY5V%2FtKf%2BHmOoJD5DfVpMySiUuDOaiIPlHI%2FtliqvuddvcDxnZQqi9tIYAxuyZOjYSG%2B9%2Fnx%2FQ%2B6m&connectionData=[{"Name":"MainHub"}]&noCache=c3d54c1d-ee78-49cc-85b4-2c87a024c32a
2013-11-25 07:47:49.203 MyApp[5163:6b03] 13:47:49.2023660 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: initialized)
2013-11-25 07:47:49.319 MyApp[5163:6b03] 13:47:49.3189120 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {"C":"s-0,CF9","S":1,"M":[]})
2013-11-25 07:47:49.332 MyApp[5163:6b03] 13:47:49.3318670 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - ChangeState(Connecting, Connected)
2013-11-25 07:47:49.634 MyApp[5163:6b03] 13:47:49.6339640 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {"C":"s-0,CFA","G":"54eYUWzlKXr9ezIoP1rZvj4DOQ00lfpXZ62PV+HwgzqCvgET2otfFNud1KzX24MjGplzkOwpyzqrVJ1jffBMyWppsDt9Tl+D25btqsxJWt6bBg3v4YfwobBKbpZaScgk/gPp5w==","M":[]})
2013-11-25 07:47:49.703 MyApp[5163:6b03] 13:47:49.7029070 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {"C":"s-0,CFB","M":[]})
2013-11-25 07:47:58.090 MyApp[5163:6b03] 13:47:58.0894910 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {})
2013-11-25 07:48:08.108 MyApp[5163:6b03] 13:48:08.1084000 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {})
2013-11-25 07:48:18.118 MyApp[5163:6b03] 13:48:18.1178390 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {})
2013-11-25 07:48:22.097 MyApp[5163:6b03] 13:48:22.0968150 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - OnMessage({"I":"0","E":"There was an error invoking Hub method 'MainHub.SignOn'."})

空的OnMessage,会在失败后每隔一段时间继续打印.

The empty OnMessage, will continue to print every so often after the failure.

更新 #2

经过测试和进一步检查后,与 LTE 与 Wifi 的相关性似乎更可能是随机的.回顾一下,在我的本地机器上运行一切正常.只是在部署到 Azure 时不会.基本上调用集线器方法会超时,随机发生.

After testing and further inspection, it seems to be more likely random than related to LTE vs Wifi. To recap, everything works fine running on my machine locally. Just not when deployed to Azure. Basically invoking a hub method will timeout, on random occurrences.

以下是我所做的一些使该问题更加罕见的事情,但它仍然发生:

Here are a few things I've done that have made the issue more rare, but it still occurs:

  1. 强制LongPollingTransport,无论如何
  2. 在成功的Start和第一个Invoke
  3. 之间添加一个Task.Delay

我在服务器上将 EnableDetailedErrors 设置为 true,这似乎是服务器端发生的事情:

I set EnableDetailedErrors to true on the server, and this seems to be what happens server side:

Error in SignOn: System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MyNamespace.MainHub.<SignOn>d__0.MoveNext(); TraceSource 'w3wp.exe' event

我认为这与客户放弃有关.我在 Azure 上看到了一些与此相关的 Github 问题,但它们被标记为已关闭..

Which, I think is just related to the client giving up. I saw some Github issues related to this on Azure, but they are marked as closed...

更新 #3

一时兴起,我将其部署到标准 Azure 网站部分,而不是云服务.之后一切正常.任何想法为什么?我显然可以为此使用 Azure 网站,但为什么它不能用作云服务?

On a whim, I deployed this to the standard Azure websites section instead of Cloud Services. Everything worked normally after that. Any ideas why? I can use Azure websites for this obviously, but why won't it work as a cloud service?

推荐答案

目前,解决方案是使用 Azure 网站而不是云服务.

For now, the solution is to use Azure websites instead of cloud services.

当我有时间时,我会创建一个repro 并将其提交到SignalR Github 问题页面.本周晚些时候应该可以做到这一点.

When I have time, I will create a repro and submit it to the SignalR Github issues page. Should be able to do that later this week.

这篇关于Xamarin.iOS 上的 SignalR - 随机无法调用集线器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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