'SecurityNegotiationException on SOAP WSDL api call in .NET core 3.1
I have a .NET core API that calls an external SOAP WSDL.
The problem that i'm facing is that there seems to be some kind of problem with the SSL certificate:
This is the full error (without the stacktrace):
System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority 'api.address.xyz'.
---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
A bit more details:
I used the WFC Web Service service reference tool from Visual Studio 2022 to create the connected service.
I'm totally new to .NET core.
I'm using Google Cloud Run.
The problem seems to present itself only when the application is deployed on Cloud Run.
What i tried:
The first thing that came to mind was installing the root and intermediate CA certificate on the server, but on Cloud Run it seems to be impossible, or at least i can't find how to do it.
I tried telling the app to accept whatever certificate it gets using this code in Program.cs:
public static IHostBuilder CreateHostBuilder(string[] args)
{
var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
var url = $"http://0.0.0.0:{port}";
//var url = "http://localhost:5001";
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().UseUrls(url).ConfigureKestrel(o =>
{
o.ConfigureHttpsDefaults(opts =>
{
opts.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
opts.AllowAnyClientCertificate();
});
});
});
}
But it does not work.
I also tried updating all possible NuGet packages that i installed and recreating the connected service but nothing.
I think i'm missing the point.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
