#.net #web-services #wcf #webservice-client
#.net #веб-сервисы #wcf #веб-сервис-клиент
Вопрос:
Я пытаюсь подключиться к веб-службе ‘https://trackingqa.estafeta.com/Service.asmx ‘программно я имею в виду, что с кодом без конфигурации (.config) я пробую это
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 (https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication#configure-the-client)
и я пытаюсь это:
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 на клиенте
Ответ №1:
Я нашел решение., работает для меня.
-
Установить протокол безопасности
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));