基于HTTPS的Xamarin Android Web服务
我在使用仅通过https提供的web服务时遇到了一些困难 我也读过其他一些人的帖子,他们在实现这一目标方面也有问题,但到目前为止,我所看到的答案都没有解决我的问题,因此我将尝试在这里解释我的问题,希望你们中的一些人知道如何克服这一障碍 我使用的是专门为Android开发的XamarinStudio6.1.1。 我已经将项目的“Android构建”下的“HttpClient实现”设置为“AndroidClientHandler”(这似乎是最新的实现,应该支持TLS 1.2) 我已经在web服务中添加了一个web引用(不是WCF),并在提示时提供了登录信息。。。到目前为止,一切都按预期进行 注意:我已经在VisualStudio中的控制台应用程序中测试了web服务,它可以正常工作 然而,当我尝试调用web服务的其中一个方法时,我得到了一个与我之前看到的许多其他方法相同的错误,即“错误:TrustFailure(身份验证或解密失败)” 我已经尝试了之前发布的几种解决方案,但似乎没有任何帮助 1.A)为ServicePointManager提供回调函数:基于HTTPS的Xamarin Android Web服务,android,web-services,xamarin,https,Android,Web Services,Xamarin,Https,我在使用仅通过https提供的web服务时遇到了一些困难 我也读过其他一些人的帖子,他们在实现这一目标方面也有问题,但到目前为止,我所看到的答案都没有解决我的问题,因此我将尝试在这里解释我的问题,希望你们中的一些人知道如何克服这一障碍 我使用的是专门为Android开发的XamarinStudio6.1.1。 我已经将项目的“Android构建”下的“HttpClient实现”设置为“AndroidClientHandler”(这似乎是最新的实现,应该支持TLS 1.2) 我已经在web服务中添
ServicePointManager.ServerCertificateValidationCallback += CertificateValidationCallBack;
1.B)回调函数:
private static bool CertificateValidationCallBack(
object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
// If the certificate is a valid, signed certificate, return true.
if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
{
return true;
}
// If there are errors in the certificate chain, look at each error to determine the cause.
if ((sslPolicyErrors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)
{
if (chain != null && chain.ChainStatus != null)
{
foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)
{
if ((certificate.Subject == certificate.Issuer) &&
(status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))
{
// Self-signed certificates with an untrusted root are valid.
continue;
}
else
{
if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
{
// If there are any other errors in the certificate chain, the certificate is invalid,
// so the method returns false.
return false;
}
}
}
}
// When processing reaches this line, the only errors in the certificate chain are
// untrusted root errors for self-signed certificates. These certificates are valid
// for default Exchange server installations, so return true.
return true;
}
else
{
// In all other cases, return false.
return false;
}
}
2) 创建AESCryptServiceProvider的实例:
System.Security.Cryptography.AesCryptoServiceProvider b = new System.Security.Cryptography.AesCryptoServiceProvider();
如果有人能解决这个显然相当普遍的问题,请不要犹豫让我知道,我只有这么多头发
亲切问候,,
Aidal可能的已知错误。在此处搜索“https”: [Mono]、[Xamarin.iOS]、[Xamarin.Android]、[Xamarin.Mac]–43566- “信任失败(身份验证或解密失败。)…无效 从服务器接收到证书。错误代码为“0x5”或“错误” 代码:0xFFFFFF800B010F“尝试访问上的HTTPS服务器时 443以外的端口
错误参考:Aha!所以这实际上是当前版本中的一个bug,这意味着无论我做什么,我都无法让它工作。在这种情况下,我想我唯一的选择是等待修复?那么,您使用的端口号是什么?443应该可以。此外,仅从认证验证回调返回
true
作为一种解决方法应该会有所帮助,但对于任何生产性应用程序都不是一个选项。端口不是443,很遗憾,我无法请求对此进行更改。我已经尝试过你提到的解决方法,但它不起作用。我已经连载了相关服务的一些回复,我正在与我的应用程序中的回复一起工作,同时希望这个问题能很快得到解决。感谢您引导我关注发布页面上的已知问题。