WinRT UWP将客户端证书附加到Web服务请求

时间:2016-03-22 09:02:10

标签: c# web-services windows-runtime win-universal-app client-certificates

WinRT中是否可以将客户端证书附加到SOAP客户端请求? 在以前的版本中,您只需执行以下操作:

MyServiceSoapClient client = new MyServiceSoapClient()
X509Certificate2 cert = CertificateHelper.GetClientCertificate();
client.ClientCredentials.ClientCertificate.Certificate = cert;

但ClientCertificate属性似乎不再可用。 我怎样才能在UWP中实现这一目标?

谢谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

var client = new ServiceClient();
client.Endpoint.Address = new EndpointAddress(url);

BasicHttpBinding binding = client.Endpoint.Binding as BasicHttpBinding;
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

client.ClientCredentials.ClientCertificate.Certificate = ...

您可以编辑证书以符合您的要求:)

服务客户端文档 https://msdn.microsoft.com/en-ca/library/mt185502.aspx

参考: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f1b8ef52-8c3e-417c-94b9-ba2a545e9beb/uwp-app-making-soap-call-requiring-clientcredential?forum=wpdevelop