1

我正在尝试使用 Xamarin 制作一个示例 Android 应用程序,以实现通过 Azure 通知中心接收通知。

我遵循了http://www.windowsazure.com/en-us/manage/services/notification-hubs/getting-started-xamarin-android/的教程

该应用程序在 Android 4 上运行良好,但在 Android 2.2 上它给了我这个消息和异常。我认为错误是由于 Xamarin.NotificationHub 中的调用而出现的:

await client.UploadStringTaskAsync(serverUrl, "POST", registrationPayload);

其中 serverUrl 是 Azure 通知中心中的端点

消息是

12-05 23:44:25.727 I/mono-stdout(642):获取响应流时出错(写入:身份验证或解密失败。):SendFailure

例外:

System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a\n  
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.RemoteValidation (Mono.Security.Protocol.Tls.ClientContext context, AlertDescription description) [0x00000] in <filename unknown>:0 \n  
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0 \n  
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0 \n  at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0 \n  
at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0 \n  
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n  --- End of inner exception stack trace ---\n  
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n  --- End of inner exception stack trace ---\n  at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 \n  
at System.Threading.Tasks.TaskFactory`1[System.IO.Stream].InnerInvoke (System.Threading.Tasks.TaskCompletionSource`1 tcs, System.Func`2 endMethod, IAsyncResult l) [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n  
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n  
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.IO.Stream].GetResult () [0x00000] in <filename unknown>:0 \n  
at System.Net.WebClient+<UploadDataTaskAsyncCore>c__asyncA.MoveNext () [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n  
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n  
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[System.Byte[]].GetResult () [0x00000] in <filename unknown>:0 \n  
at System.Net.WebClient+<UploadStringTaskAsync>c__asyncD.MoveNext () [0x00000] in <filename unknown>:0 \n--- End of stack trace from previous location where exception was thrown ---\n  
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n  
at System.Runtime.CompilerServices.TaskAwaiter`1[System.String].GetResult () [0x00000] in <filename unknown>:0 \n  
at ByteSmith.WindowsAzure.Messaging.NotificationHub+<CreateRegistration>d__33.MoveNext () [0x0012c] in e:\\Projects\\Xamarin\\TestNotificationHub2\\Client\\TestNotificationHub2\\Xamarin.NotificationHub-master\\source\\ByteSmith.WindowsAzure.Messaging\\NotificationHub.cs:415 \n--- End of stack trace from previous location where exception was thrown ---\n  
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n  
at System.Runtime.CompilerServices.TaskAwaiter`1[ByteSmith.WindowsAzure.Messaging.Registration].GetResult () [0x00000] in <filename unknown>:0 \n  
at ByteSmith.WindowsAzure.Messaging.NotificationHub+<Register>d__23.MoveNext () [0x00151] in e:\\Projects\\Xamarin\\TestNotificationHub2\\Client\\TestNotificationHub2\\Xamarin.NotificationHub-master\\source\\ByteSmith.WindowsAzure.Messaging\\NotificationHub.cs:314 \n--- End of stack trace from previous location where exception was thrown ---\n  
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 \n  
at System.Runtime.CompilerServices.TaskAwaiter`1[ByteSmith.WindowsAzure.Messaging.Registration].GetResult () [0x00000] in <filename unknown>:0 \n

我相信单声道中的 https 证书可能存在问题,不确定也不知道如何解决。

4

1 回答 1

0

看来我是对的。这里的代码解决了这个问题:

http://slodge.blogspot.ro/2012/11/ssl-problems-with-microsoft-azure.html

感谢 Stuart 分享代码。

我仍然不知道处理这个问题的最佳方法是什么。X

于 2013-12-05T22:42:18.063 回答