我们有一个 Xamarin Android 应用程序,它使用WCF与服务器通信。(“只需使用 REST。”我同意。出于这个问题的目的,假设我们必须使用 WCF,我称之为“遗留原因”。)
这一切都有效。
但是,现在我们有一个客户希望 Android 设备在与服务器通信时使用客户端证书。我找到了一些在 Xamarin 中构建的示例代码:
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var endpoint = new EndpointAddress(serviceURL);
var client = new MyAppCommServiceClient(binding, endpoint);
// Specify a certificate to use for authenticating the client.
client.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.CurrentUser,
StoreName.My,
X509FindType.FindBySubjectName,
certSubjectName);
问题是我运行这个,调用SetCertificate()抛出一个System.NotImplementedException.
我的问题是:在 Xamarin Android 中是否有另一种方法告诉 WCF 客户端(派生自System.ServiceModel.ClientBase)使用特定的客户端证书?
我们在 Android 设备上安装了客户端证书。如果有帮助,它也可以作为单独的.pfx文件使用(我们的应用程序可以读取文件系统)。另请注意,我对在 PCL 中不起作用的解决方案持开放态度。