Windows ServerCore - HttpSendRequest ends in Operation aborted - docker

I have a .NET(x64) console application (RPC-Endpoint) programmed with Delphi running in a windows/servercore docker container. That RCP-Endpoint calls a soap interface in the background to gather some further data.
When I run this RPC-Endpoint on the servercore and the application tries to call the soap-endpoint, it stops with the error Operation aborted at Soap.SOAPHTTPTrans.SOAPHTTPTrans.THTTPReqResp.Send.
Now my guess is that something is wrong with the WinINET library on the servercore, because the Delphi SOAP-Client uses the HttpSendRequest function from the WinApi.WinINET library to call a SOAP-Endpoint.
Now my question is, is there any package that needs be installed on the windows/servercore so that the application can call an soap-endpoint without getting the Operation aborted error?

Related

Catch X11 XIO errors

I have an OpenGL / GLFW (which uses X11) app running inside a Docker container, starting when the PC starts. I have it installed on 2 differents PCs.
On the first one (an Intel NUC Enthusiast with an RTX 2060), everything works fine.
On the second one (a Dell Precision 7920 with a Quadro A6000), it crashes when starting on PC boot, but works fine when restarting it manually a bit later. The error is the following:
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server
":0" after 170 requests (170 known processed) with 0 events remaining.
It is triggered by a call to glfwPollEvents(); in my app's main loop. Seems my app is started a bit too early by Docker and that something is not started yet.
Then the app crashes with an exit code of 0, which me unable to workaround the problem using Docker's "on-failure" restart policy. Using the "always" policy works, but I'd prefer to avoid it.
So I'd like to catch this XIO exception, either to see if ignoring it for a while is enough, or to send a non-zero exit code so that Docker restarts the app until it works.
Is it possible? I have tried glfwSetErrorCallback & XSetErrorHandler, neither is called...
Maybe too late, but still:
If you get an XIO error, maybe setting the appropriate error handler could be the right thing to do.
XSetIOErrorHandler
The XSetIOErrorHandler() sets the fatal I/O error handler. Xlib calls the program's supplied error handler if any sort of system call error occurs (for example, the connection to the server was lost). This is assumed to be a fatal condition, and the called routine should not return. If the I/O error handler does return, the client process exits.

Alternative to Application.DelayInitialize for Delphi 7 Service?

Is there an alternative to Application.DelayInitialize for Delphi 7? I'm trying to create a Delphi 7 Service that hosts a COM Server but it doesn't work and I believe it is because I'm not using Application.DelayInitialize.
Re: Windows Service / DelayInitialize
I have written several COM-hosting services using BCB6, and they all work fine in all Windows versions from Win9x onwards, so I have had to deal with this same issue many times.
Simply don't call Application.Initialize() at process startup on Win2003+, wait until the TService's OnStart or OnExecute event to call it. That way, the service API is running before any COM objects are initialized.
The trick is to delay the call to Application.Initialize() ONLY on Win2003+ and ONLY when the service is actually running. DO NOT delay the call if either:
The service is running on Windows versions earlier than 2003.
when the service is being (un)installed.
when the COM object is being (un)registered.
Under those conditions, call Application.Initialize() normally at process startup.
So, you will need to check the OS version and the command line parameters to know when to call Application.Initialize() correctly.

Inno Setup tries uninstalling Delphi TService multiple times

I have a Windows Service built with Delphi 2010, and I'm using a Inno Setup installer for deployment.
It's mostly working smoothly - I correctly stop the service before uninstalls and upgrades, and restart it following installs.
[Run]
Filename: {app}\MyService.exe; Parameters: "/INSTALL /SILENT"; ...
[UninstallRun]
Filename: {app}\MyService.exe; Parameters: "/UNINSTALL /SILENT"; ...`
However, I have one problem left: If I run the installer twice in succession, then the next time I uninstall it fails showing a Message Dialog : Service XXX failed to uninstall with error: "System Error. Code:1060. The specified service does no exist."
Logging shows that the "UninstallRun" section is being executed twice when the uninstaller runs. And the second time, it fails and throws the error message (from TServiceApplication::RegisterServices) because the service is already uninstalled. Pretty sure this is because of the way Inno Setup tracks multiple installations in uninstall.dat.
My 'hack' to fix this is to use the TService's ServiceBeforeUninstall handler, and exit(0) if the service isn't installed. This feels like a brute force approach - is there a smarter way of resolving the problem?
Don't use the built-in SCM wrapper functions in TService, use the SCM API, they will give you much more control on service management. I wrote an InnoSetup script years ago, you can find it here - it's a while I don't update it, but it is still a starting point.

How to stop a Delphi 6 COM server application re-registering with COM at startup

I have a set of legacy Delphi 6 aplications that are out of process COM servers. In attempting to run these programs as a normal domain user on Windows I see them when running up (without any command line arguments or switches) attempting to update chunks of HKEY_CURRENT_CLASSES. this fails due to lac of permission to the HKCR hive. It appears that the act of running a Delphi 6 COM server causes it to attempt to register its embedded COM types with the system registry.
I do not want this behavior normally. We would do this once during install under and adminatrative account to initalise the COM registry, but would not want to do this under normal running conditions of a non adminastrative account. (if you moniroy the system with sys internals process monitor you can see the failed registry key access attempts).
Is there a command line switch I can pass to a Delphi 6 COM server to prevent this automatic COM registrtion logic?
I don't think you're actually seeing what you think you are...
Delphi only tries to install COM servers if they haven't already been installed. I suspect what you're seeing is your application checking to see if it's registered yet or not. The reason you're seeing the failures is because back in Delphi 6 the registry key would have been opened with ALL_ACCESS rights (D6 was prior to XP/Vista/Win7), and I think that's what's causing your failed registry access attempts.
In answer to your question, though: No, there's no command line switch to prevent the automatic registration logic.
It will always try to register the server from TComServer.Initialize unless the startup parameter is /UNREGSERVER which will remove the registry settings. If the startup parameter is /REGSERVER you will get an exception if the registration failed otherwise it will just swallow the exception. Automatic registration of out-proc COM servers has been removed in later version of Delphi. The only option you have to remove this behavior in Delphi 6 is to modify TComServer.Inititalize to only register the server when FStartMode is smRegServer or smUnregServer.

How to tell if process is run by the Service Control Manager

I have a few Windows Services written in C# that I have setup to support being run from the command line as a console app if a specific parameter is passed. Works great but I would love to be able to detect whether the app is being run by the service control mananger or from a command line.
Is there any way to tell at runtime if my app was started by the SCM?
Environment.UserInteractive will return false if the process is running under the SCM.
The SCM will call your OnStart method, so you could mark that event and make sure when you run from the command line, you don't call OnStart. Or, you could check the startup parameters to see how the application was started.
In C the function StartServiceCtrlDispatcher() will fail with ERROR_FAILED_SERVICE_CONTROLLER_CONNECT. This is the best way in C, wonder if C# exposes any of this?
ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
This error is returned if the program is being run as a console application rather than as a service. If the program will be run as a console application for debugging purposes, structure it such that service-specific code is not called when this error is returned.

Resources