The first thing I made before report this problem was reading the documentation in which is written:
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.
Finally I had to set the system variable PGSERVICEFILE = D:\PostgreSQLx86\9.6\etc\pg_service.conf
After that I was been able to connect to PostgreSQL server by defined service name from machine where PosrgreSQL was installed.
Using PGAdmin 3 which comes with PostgreSQL I have to set the host IP or name. Without that the OK button on the connection form is inactive. (PGAdmin 4 doesn't need the IP/host name, what is proper).
So it seems to be a bug in PGAdmin 3, which require host IP/name to use service connection.
2. On the client side:
As you described, the PGSERVICEFILE must be set and leads into existing file.
But this option is not acceptable of the security, because login and password must be stored on local machine, in one of ways: - inside the pg_service.conf - or in c:\Users\<user_name>\AppData\Roaming\postgresql\pgpass.conf file.
Both of them are plain text file.
I was hope the storing only information of host, port, dbname (and user) in pg_service.conf file (on client) and login credentials in c:\Users\<user_name>\AppData\Roaming\postgresql\pgpass.conf file on the server would be enough to establish connection, but it didn't work either.
3. Jeff told about 'ident' mode defined in pg_hba.conf, but this kind of connections is based on windows user login name. As I understand, this type of login needn't password. Is it possible to use username from pg_service.conf file instead windows user name ?
I need it all to hide connection properties in QGIS and make QGIS project independent from servers used in different places.