简体   繁体   English

Xamarin.iOS上的SignalR - 随机无法调用Hub方法

[英]SignalR on Xamarin.iOS - randomly not able to call Hub method

I have a simple Hub running in Azure, that I have working perfectly from a console app in Windows. 我有一个在Azure中运行的简单Hub ,我在Windows中的控制台应用程序中完美运行。

I just built a simple test Xamarin.iOS app, and it is giving some strange behavior. 我刚刚构建了一个简单的测试Xamarin.iOS应用程序,它给出了一些奇怪的行为。

  1. Randomly on LTE/Wifi or Simulator/Device - invoking a hub method fails with There was an error invoking Hub method X 随机在LTE / Wifi或模拟器/设备上 - 调用集线器方法失败, There was an error invoking Hub method X
  2. Randomly about 50% - everything works perfectly just like the console app on Windows - the two are even sending messages to one another 随机约50% - 一切都像Windows上的控制台应用程序一样完美 - 两者甚至互相发送消息

I tested this on an iPhone 5S and iPhone 4S for devices. 我在iPhone 5S和iPhone 4S上测试了这个设备。

Any ideas on why this would happen? 关于为什么会这样的想法? I'm using the Portable NuGet package on version 2.0.0. 我在版本2.0.0上使用Portable NuGet包。

UPDATE: 更新:

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'."})

The empty OnMessage , will continue to print every so often after the failure. 空的OnMessage将在故障后继续打印。

UPDATE #2 更新#2

After testing and further inspection, it seems to be more likely random than related to LTE vs Wifi. 经过测试和进一步检查,它似乎更可能是随机的,而不是与LTE相关的Wifi。 To recap, everything works fine running on my machine locally. 总结一下,一切都在我的机器本地运行良好。 Just not when deployed to Azure. 只是在部署到Azure时没有。 Basically invoking a hub method will timeout, on random occurrences. 在随机发生时,基本上调用hub方法将超时。

Here are a few things I've done that have made the issue more rare, but it still occurs: 以下是我所做的一些使问题更加罕见的事情,但它仍然会发生:

  1. Force LongPollingTransport , no matter what 强制LongPollingTransport ,无论如何
  2. Add a Task.Delay in between a successful Start and the first Invoke 在成功的Start和第一个Invoke之间添加Task.Delay

I set EnableDetailedErrors to true on the server, and this seems to be what happens server side: 我在服务器上将EnableDetailedErrors设置为true ,这似乎是服务器端发生的事情:

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

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... 我在Azure上看到了与此相关的一些Github问题 ,但它们被标记为已关闭...

UPDATE #3 更新#3

On a whim, I deployed this to the standard Azure websites section instead of Cloud Services. 一时兴起,我将其部署到标准Azure网站部分而不是云服务。 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. 目前,解决方案是使用Azure网站而不是云服务。

When I have time, I will create a repro and submit it to the SignalR Github issues page. 当我有时间时,我将创建一个repro并将其提交给SignalR Github问题页面。 Should be able to do that later this week. 应该可以在本周晚些时候这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM