System.Security.Authentication.AuthenticationException: 'The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch, RemoteCertificateChainErrors'
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
We are migrating our worker service from .NET 4.8 to .NET 6(latest version).
We have created a Connected Service using existing WSDL but when we try to Invoke method we are getting error in terms of invalid certificate Code
we are using Generated methods from Connected Service. to connect
Code:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;
ServicePointManager.Expect100Continue = true;
HttpsTransportBindingElement secureTransport = new HttpsTransportBindingElement
{
MaxReceivedMessageSize = maxBufferSize,
MaxBufferSize = maxBufferSize,
RequireClientCertificate = true,
};
CustomBinding binding = new CustomBinding();
binding.Elements.Add(bindingElement ?? new TextMessageEncodingBindingElement(MessageVersion.Soap11,
System.Text.Encoding.UTF8));
binding.Elements.Add(secureTransport);
binding.SendTimeout = TimeSpan.FromSeconds(sendTimeout);
binding.ReceiveTimeout = TimeSpan.FromSeconds(receiveTimeout);
var endPoint = new EndpointAddress($"https://{IP}/{urlName}/");
var service = new ServiceReference1.PortTypeWSBClient(binding, endPoint); //Generated code
foreach (var endpointBehavior in endpointBehaviors ?? new IEndpointBehavior[0])
service.Endpoint.EndpointBehaviors.Add(endpointBehavior);
service.Endpoint.EndpointBehaviors.Add(this.MessageLogger);
service.ClientCredentials.ClientCertificate.Certificate = LoadCertificate();
service.Open();
Old code (.net 4.8) and SoapUI on same machine works fine
Contributor guide
Assessment
This issue has not been assessed yet.