admin管理员组文章数量:1335356
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) inOccurred 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:
- On my local machine, both the console app and MSI installer work fine.
- On the production system:
- Console app works for both HTTP and HTTPS.
- MSI installer fails for HTTPS.
- Network Connectivity:
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:
Local System:
Windows 10
.NET Framework 4.8
HTTPS works in both Console App and MSI Installer.
Production System:
Windows Server 2019
HTTPS works in Console App but fails in MSI Installer.
HTTP works fine in both Console App and MSI Installer.
What I Need Help With:
Why does the HTTPS request fail in the MSI installer but work in the console application?
Could it be related to the installer’s execution context, permissions, or environment settings? If so, how do I debug or resolve this?
Are there specific configurations required for the WiX installer to support HTTPS calls during installation?
Any insights or suggestions are greatly appreciated.
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) inOccurred 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:
- On my local machine, both the console app and MSI installer work fine.
- On the production system:
- Console app works for both HTTP and HTTPS.
- MSI installer fails for HTTPS.
- Network Connectivity:
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:
Local System:
Windows 10
.NET Framework 4.8
HTTPS works in both Console App and MSI Installer.
Production System:
Windows Server 2019
HTTPS works in Console App but fails in MSI Installer.
HTTP works fine in both Console App and MSI Installer.
What I Need Help With:
Why does the HTTPS request fail in the MSI installer but work in the console application?
Could it be related to the installer’s execution context, permissions, or environment settings? If so, how do I debug or resolve this?
Are there specific configurations required for the WiX installer to support HTTPS calls during installation?
Any insights or suggestions are greatly appreciated.
Share Improve this question edited Nov 20, 2024 at 23:36 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 20, 2024 at 9:29 Meet GajjarMeet Gajjar 113 bronze badges 2 |2 Answers
Reset to default 0Could 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.
postgres:
connection:
url: "jdbc:postgresql://your-postgresql-server:5444/your-database"
username: ${POSTGRES_USERNAME}
password: ${POSTGRES_PASSWORD}
本文标签: cHTTPS API Calls Failing in WiX MSI Installer While Working in Console AppStack Overflow
版权声明:本文标题:c# - HTTPS API Calls Failing in WiX MSI Installer While Working in Console App - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742368897a2461832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<CustomAction Id="CallAPI" BinaryKey="CustomActionsBin" DllEntry="callapiexe" Execute="immediate" Return="check" Impersonate="yes"/>
– Meet Gajjar Commented Nov 21, 2024 at 10:17