.net net WCF客户端配置htts
我正在尝试连接到web服务的https://trackingqa.estafeta.com/Service.asmx'编程上,我的意思是没有配置的代码(.config) 我试试这个.net net WCF客户端配置htts,.net,web-services,wcf,webservice-client,.net,Web Services,Wcf,Webservice Client,我正在尝试连接到web服务的https://trackingqa.estafeta.com/Service.asmx'编程上,我的意思是没有配置的代码(.config) 我试试这个 BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentia
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
EndpointAddress endpoint = new EndpointAddress(url);
ServiceSoapClient client = new ServiceSoapClient(binding, endpoint);
但我得到了这个错误:
未提供客户端证书。在ClientCredentials中指定客户端证书
我在MSDN()上找到了此文档
我试着这样做:
client.ClientCredentials.ClientCertificate.SetCertificate(
System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser,
System.Security.Cryptography.X509Certificates.StoreName.My,
System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName, "TrackingQA.estafeta.com");
但是我得到了这个错误:
异常:找不到具有以下搜索条件的X.509证书:StoreName“My”、StoreLocation“CurrentUser”、FindType“FindBySubjectName”、FindValue“TrackingQA.estafeta.com”
我的问题是如何在客户端配置de endpoint我找到了一个解决方案。,
对我有用
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.ClientCredentials.ClientCertificate.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Convert.FromBase64String(StringCertificateBase64));
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
EndpointAddress endpoint = new EndpointAddress(url);
ServiceSoapClient client= new ServiceSoapClient(binding, endpoint);
client.ClientCredentials.ClientCertificate.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Convert.FromBase64String(StringCertificateBase64));