Meet Gajjar
Meet Gajjar

Reputation: 11

HTTPS API Calls Failing in WiX MSI Installer While Working in Console App

I’m developing a custom installer using the WiX Toolset for a .NET Framework 4.8 application. During the installation process, I need to make an HTTPS API call. The API call works perfectly in a standalone console application but consistently fails when executed from the MSI installer.

Problem Details:
The API call works with both HTTP and HTTPS in the console application. In the MSI installer, HTTP requests succeed, but HTTPS requests fail with the following error

Error :

An error occurred while server Configration : WebException occurred during API call: https://{Domain}:443/api/RPA/RpaSetupLog
Status: ReceiveFailure
Response:
Message: The underlying connection was closed: An unexpected error occurred on a receive.
Stack trace: at System.Net. HttpWebRequest.GetResponseO at CustomActions. CustomActions. SendDataToApi(String protocol, String domainOrlp, String port, String jsonData, String rootCertificateString, String intermediateCertificateString, String endDomainCertificateString) in

Occurred at line: O

So the problem is, I had a Wix installer for that I have MSI installer, in that when I try to call API with https protocol, it give me error, but in normal http it succeeds and the when I create one console app, with same parameter, and same function and try to call it succeeds, I got problem, with https in .msi installer, I also add this line

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

The same in console app, it works, but in MSI installer it fails.

Checked Certificates:

Ensured that the server uses a valid certificate. For self-signed certificates, I’ve manually installed the root, intermediate, and domain certificates in the production system's certificate store. Tested on Different Environments:

Verified that the production system can resolve and ping the API domain. HTTP requests from the MSI installer succeed, indicating network access is available.

Code:

private static bool SendDataToApi(string protocol, string domainOrIp, string port, string jsonData)
{
    string apiUrl = $"{protocol}://{domainOrIp}:{port}/api/RPA/RpaSetupLogs";

    try
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiUrl);
        request.Method = "POST";
        request.ContentType = "application/json";
        request.Timeout = 30000;

        // Enable TLS 1.2
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        // Bypass SSL Validation (Tried this as a workaround)
        ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

        using (var writer = new StreamWriter(request.GetRequestStream()))
        {
            writer.Write(jsonData);
            writer.Flush();
        }

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new InvalidOperationException($"API call failed with status: {response.StatusCode}");
            }
        }

        return true;
    }
    catch (WebException webEx)
    {
        Console.WriteLine($"WebException: {webEx.Message}, Status: {webEx.Status}");
        throw;
    }
}

Environment Details:

What I Need Help With:

  1. Why does the HTTPS request fail in the MSI installer but work in the console application?

  2. Could it be related to the installer’s execution context, permissions, or environment settings? If so, how do I debug or resolve this?

  3. Are there specific configurations required for the WiX installer to support HTTPS calls during installation?

Any insights or suggestions are greatly appreciated.

Upvotes: 1

Views: 60

Answers (2)

Ricky
Ricky

Reputation: 1

postgres:
  connection:
    url: "jdbc:postgresql://your-postgresql-server:5444/your-database"
    username: ${POSTGRES_USERNAME}
    password: ${POSTGRES_PASSWORD}

Upvotes: -1

Nikolay
Nikolay

Reputation: 12245

Could it be that your custom action is executed as "system" (i.e. with different user profile). To reproduce: run your console app as system (i.e. under that account under which the installation happens).

Or you can run your action as the current user. Then the result should match your console app.

<CustomAction 
  ...
  Impersonate="yes"
  ...
/>

BTW you probably don't actually need a separate console app, I think you could use Debugger.Launch and Debugger.Break to start the debugger from the custom action.

Upvotes: 0

Related Questions