The connection service file can be: - a per-user service file at ~/.pg_service.conf - or the location specified by the environment variable PGSERVICEFILE - or it can be a system-wide file at `pg_config --sysconfdir`/pg_service.conf - or in the directory specified by the environment variable PGSYSCONFDIR.
The last point talks the service file could placed into PGSYSCONFDIR. Using PostrgeSQL on Windows the PGSYSCONFDIR leads into D:\PostgreSQLx86\9.6\etc folder as a result of PG_config.exe. This folder normally is absent. I created it manually and then copy into it the pg_service.conf file.
So the bug is that the pg_service.conf file is not read from this location.
I can reproduce this after using the EDB installer to install.
I create the directory indicated by `pg_config --sysconfdir`, put the pg_service.conf in it, and psql and pg_dump work without setting either PGSERVICEFILE or PGSYSCONFDIR. But pgbench and PgAdmin4 do not work with the service file this way, but do work if I define PGSERVICEFILE, so there does seem to be something buggy going on.