Home > Enterprise >  Simple.OData.Client: Could not create SSL/TLS secure channel
Simple.OData.Client: Could not create SSL/TLS secure channel

Time:10-21

I have an OData Excel plugin developed using Simple.OData.Client. The Application was working fine but now I get the message:

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel

ODataClientSettings odcSettings = new ODataClientSettings();
                    //Define the URL
                    Uri uriOdata = new Uri(datosDeConexion.Url);
                    odcSettings.BaseUri = uriOdata;
                    odcSettings.Credentials = new NetworkCredential(datosDeConexion.Username, datosDeConexion.Password);                    
                    odcSettings.BeforeRequest = requestMessage =>
                    {
                        requestMessage.Headers.Accept.Clear();
                        requestMessage.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                        requestMessage.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
                    };

                    /*
                    We establish the connection and we bring the metadata to know if it is connected
                    */
                    ODataClient client = new ODataClient(odcSettings);

                    IEdmModel metadata = await client.GetMetadataAsync<IEdmModel>();
                    var entityTypes = metadata.SchemaElements.OfType<IEdmEntityType>().ToArray();
                    label1.Text = "Connection successful";
                    label1.ForeColor = Color.Green;
                    button2.Enabled = true;               

We did not change the code or the libraries but upgraded the provider to Ubuntu 22.04.1 LTS

I have been looking around for this error but I cannot understand a solution that would apply to Simple.OData.Client. We are using Simple.OData.Client version 5.26.0.0 If I use the standard OData connector from Excel (Data->Get Data->From Other sources-> OData feed) it works fine however my code does not. Which means that I need fix it but I don't know how.

We don't have a problem with our certificate

Any idea is appreciated

CodePudding user response:

try to add this code above your code block

    System.Net.ServicePointManager.SecurityProtocol =
        SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

    ODataClientSettings odcSettings = new ODataClientSettings();
...

You can find explanation here: https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls

  • Related