#1 2012-08-26 21:22:46

paulh
Member
Registered: 2012-05-12
Posts: 44

Proxy configuration settings in client

Hi Arnaud

Thanks for your software, my application uses it extensively for transmitting data to and from client and server over HTTP and it has helped save me write serialisation and send/receive code.
I need to ensure my application will work behind corporate firewalls where a proxy server is in place.
I note the following from your documentation:

Note that even if WinHTTP does not share by default any proxy settings with Internet Explorer, it can import the current IE settings. The WinHTTP proxy configuration is set by either proxycfg.exe on Windows XP and Windows Server 2003 or earlier, either netsh.exe on Windows Vista and Windows Server 2008 or later; for instance, you can run "proxycfg -u" or "netsh winhttp import proxy source=ie" to use the current user's proxy settings for Internet Explorer. Under 64 bit Vista/Seven, to configure applications using the 32 bit WinHttp settings, call netsh or proxycfg bits from %SystemRoot%\SysWOW64 folder explicitly.

I want to include in my client application the ability to detect the proxy settings if possible and if necessary to allow the user to enter the proxy details in my application and have it use those. I'm connecting to the server (an EC2 instance on Amazon cloud) using:

    if FModel=nil then
      FModel := TSQLModel.Create([],ROOT_NAME);
    FClient := TSQLite3HttpClient.Create(SERVER_IP,COMMS_PORT,FModel);
    FClient.SetUser(UPARAM1,UPARAM2);
    FClient.ServiceRegister([TypeInfo(IERefServerInterface)],sicShared);

How do I specify the proxy server details in my code if netsh/proxycfg can't get details?

Regards

Paul

Offline

#2 2012-08-27 06:04:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Proxy configuration settings in client

You are right, there was some optional parameters missing to set easily the proxy settings by hand.

See http://synopse.info/fossil/info/5c7d491126
  *  added optional aProxyName, aProxyByPass parameters to TWinHttpAPI / TWinInet and TWinHTTP constructors
  *  added optional aProxyName, aProxyByPass parameters to TSQLite3HttpClientWinGeneric / TSQLite3HttpClientWinINet and TSQLite3HttpClientWinHTTP constructors

Now you can specify your proxy settings without netsh/proxycfg.

Thanks for the feedback!

Offline

#3 2012-08-29 21:35:28

paulh
Member
Registered: 2012-05-12
Posts: 44

Re: Proxy configuration settings in client

Hi Arnaud, that's great, I'll get the latest version and try it out - it's just what I need.
Regards
Paul

Offline

#4 2012-09-04 00:48:31

paulh
Member
Registered: 2012-05-12
Posts: 44

Re: Proxy configuration settings in client

Hi Arnaud, I've upgraded to the latest version and now all of a sudden I'm getting an error trying to establish a connection from the client to the server.

It fails with the following exception:
Error in TClientToServer.doConnect: "ERefServerInterface" interface or REST routing not supported by server: {
"ErrorCode":403,
"ErrorText":"Forbidden"
}

This code is raised by:
constructor TServiceFactoryClient.Create(aRest: TSQLRest;
  aInterface: PTypeInfo; aInstanceCreation: TServiceInstanceImplementation;
  const aContractExpected: RawUTF8);
var i, siz: integer;
    P: PCardinal;
    Error, RemoteContract: RawUTF8;
begin
  // extract RTTI from the interface
  if not aRest.InheritsFrom(TSQLRestClientURI) then
    EServiceException.CreateFmt('%s interface needs a Client connection',
      [aInterface^.Name]);
  inherited Create(aRest,aInterface,aInstanceCreation);
  // check if this interface is supported on the server
  if aContractExpected<>'' then
    fContractExpected := aContractExpected; // override default contract
  if not CallClient(SERVICE_PSEUDO_METHOD[imContract],@Error,'',@RemoteContract) then
    raise EServiceException.CreateFmt('"%s" interface or %s routing not supported by server%s',
      [fInterfaceURI,GetEnumNameTrimed(TypeInfo(TServiceRoutingMode),fRest.ServicesRouting),Error]);

What has changed that is not backwards compatible?

Thanks

Paul

Offline

#5 2012-09-04 01:10:29

paulh
Member
Registered: 2012-05-12
Posts: 44

Re: Proxy configuration settings in client

P.S. This is the code I'm using to connect which causes the code to fail:

procedure TClientToServer.doConnect;
var
  I:  IERefServerInterface;
begin
  // Run procedure to get the proxy info into FProxyInfo
  extractProxyInfo;

  if FClient=nil then begin
    if FModel=nil then
      FModel := TSQLModel.Create([],ROOT_NAME);
    FClient := TSQLite3HttpClient.Create(SERVER_IP,COMMS_PORT,FModel,false,FProxyInfo.ProxyURL,FProxyInfo.ProxyBypass);
    FClient.SetUser(MOR_USER,MOR_PASS);
    try
      FClient.ServiceRegister([TypeInfo(IERefServerInterface)],sicShared);
    except
      on e: exception do
        logmsg('Error in TClientToServer.doConnect: '+e.message);
    end;
  end;
  if FClient.Services['ERefServerInterface'].Get(I) then
  begin
    FMainInterface := I;
  end;
end;


I reverted to the older version of the Mormot code and it runs just fine so this is some incompatibility that has been introduced sad

Paul

Offline

#6 2012-09-04 06:27:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Proxy configuration settings in client

Did you recompile both client and server side ?

Error comes from not matching interface on both side.

Offline

#7 2012-09-04 07:25:32

paulh
Member
Registered: 2012-05-12
Posts: 44

Re: Proxy configuration settings in client

Hi Arnaud, yes, absolutely - they are part of a group so I always recompile both. Furthermore if I change the path to the older Synopse source folder then it all worked.
One thing I must check though is whether I made sure the newer sqlite3.obj files are in the path...
Paul

Last edited by paulh (2012-09-04 07:30:35)

Offline

#8 2012-09-04 07:38:41

paulh
Member
Registered: 2012-05-12
Posts: 44

Re: Proxy configuration settings in client

Arnaud, I double-checked and is failing with the latest version and latest .obj files and building both client and server.
If I change the path to the original Synopse folder and recompile both they work fine.
Any other ideas of how I can find the issue?
Thanks
Paul

Offline

#9 2012-09-04 09:49:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Proxy configuration settings in client

Check also that:
- You use correct Include path in both Client and Source projects (points to the very same version of the framework, and rename the old one to be sure);
- You do not use `string` type with pre-Unicode version of Delphi, with two diverse code pages on the computers.

The regression tests about that passed OK, contracts are checked between client and server as expected, so I was unable to find out what is wrong here.
Your supplied code is not enough to find out the error cause.

Please check the fContract and fContractHash computed on both sides, in TServiceFactory.Create.
Is the fContractHash comparison failing?

Offline

#10 2012-09-04 13:16:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Proxy configuration settings in client

Could you run the integration tests in TestSQL3.dpr?

Try also the Interface-based service samples programs available in http://synopse.info/fossil/dir?name=SQL … d+services.

They should work as it does here.

Offline

#11 2012-09-04 20:05:27

paulh
Member
Registered: 2012-05-12
Posts: 44

Re: Proxy configuration settings in client

Hi Arnaud, I can't run the integration tests just now but I have been able to narrow this down quite considerably by testing building the client with the new version of your code against the server built with the old version and that works so it looks like the incompatibility is on the server side.
If I build the server with the new code it compiles okay but is rejecting the client.
I shall look at your interface-based service samples to see if anything is different...

Offline

#12 2012-09-04 21:25:44

paulh
Member
Registered: 2012-05-12
Posts: 44

Re: Proxy configuration settings in client

Arnaud, I couldn't see anything obvious but it is taking too long to try and resolve the issue so I've applied the additional code you'd added for passing the proxy settings into the old code base that I have and that is working for me now. It just means that I'm isolated with the old code base but it is working fine so I'm not too perturbed by that just now.
Thanks for the assistance as ever. At some point I'll try again to find what's causing it not to work...

Offline

#13 2012-09-04 21:39:24

paulh
Member
Registered: 2012-05-12
Posts: 44

Re: Proxy configuration settings in client

P.S. I did check and the contracthash is the same in the client and the server for both the old and the new code - so it is not due to a difference in the hash.

Offline

#14 2012-09-05 11:21:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Proxy configuration settings in client

Could you step into the server side code using the debugger to guess why CallClient() returns false?

See what occurs in TSQLRestServer.URI for this request.

Offline

#15 2020-07-07 16:11:16

George
Member
Registered: 2016-04-05
Posts: 140

Re: Proxy configuration settings in client

aProxyName seems a string, that must contain proxy server address and i guess a port.
Is it possible to set proxy login and password somehow?
---
Basic authentication on proxy, probably, can be implemented via request headers.

Last edited by George (2020-08-10 11:16:37)

Offline

Board footer

Powered by FluxBB