Reputation: 161
I am trying to connect to a web service 'https://trackingqa.estafeta.com/Service.asmx' programaticaly what i mean is with code no configuration (.config) I try this
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
EndpointAddress endpoint = new EndpointAddress(url);
ServiceSoapClient client = new ServiceSoapClient(binding, endpoint);
but i get this error:
The client certificate is not provided. Specify a client certificate in ClientCredentials.
i found this doc on MSDN (https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication#configure-the-client)
and i try this:
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");
but i getting this error:
Exception: Cannot find X.509 certificate with the following search criteria: StoreName 'My', StoreLocation 'CurrentUser', FindType 'FindBySubjectName', FindValue 'TrackingQA.estafeta.com'.
my question is how configure de endpoint in the client
Upvotes: 0
Views: 198
Reputation: 161
I found a solution., Works for me.
Set security protocol
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
set certificate
client.ClientCredentials.ClientCertificate.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Convert.FromBase64String(StringCertificateBase64));
complete code:
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));
Upvotes: 0