#1 2012-09-07 08:37:34

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Opening a remote database through Client-server services

I'm trying to accomplish the following setup:

I have a "generic" server process "LCSRestServer" running, implementing a very simple interface with a TSQLRestServerDB instance. This server uses its own very simple TLCSServerModel = class(TSQLModel).

type
  ILCS = interface(IInvokable)
    ['{31969E17-758B-4077-B0E8-77B81B082715}']
    {1 open the database as specified in the connectionstring, return if this was succesfull
        - aConnectionstring contains all info needed to connect using <protocol>://server/name syntax
        - if aCreate is true than create the database if it doent exist
    }
    function OpenDatabase(aConnectionString: RawUTF8; var URI: RawUTF8; aCreate: boolean = false): boolean;
  end;

The client process can now tell the server to open the specified database, making it available to the client. This database is implementing a different TSQLModel ("TLCSModel"), the RestServer must be implementing a different interface "ILCSDatabase"

The implementation of the OpenDatabase method being:

function TLCSServer.OpenDatabase(aConnectionString: RawUTF8; var URI: RawUTF8; aCreate: boolean = false): boolean;
var
  ...
begin
    //Determine database type and protocol
    lConProp := CreateConnectionProperties(aConnectionString);

    if lConProp <> nil then
    begin
      //Create separate TSQLRestSeverDB object for this database

      lModel := TLCSModel.Create(URI);
      lModel.RegisterVirtualTables(lConProp);

      lRestServerDB := TLCSRestDB.Create(lModel, UTF8ToString(URI) + '.db3');
      lRestServerDB.CreateMissingTables;

      lRestServerDB.ServiceRegister(TLCSDatabase , [TypeInfo(ILCSDatabase)], sicShared);

      //Register the new restServer with the http server of the main server process
      LCSRestServer.RegisterDatabase(lRestServerDB);

      Result := true;
    end;
  end;

Somehow i'm not getting this whole setup working... The above method does work, but when i try to run the following method on the client side, it says it can't find LCSDatabase as a service on the server ...

  FModel := TLCSModel.Create(cURI);
  FClient := TSQLite3HttpClient.Create('localhost','888',FModel);
  FClient.ServiceRegister([TypeInfo(ILCS)],sicShared);

  FClient.Services[cURI].Get(FLcsInterface);

  FLcsInterface.OpenDatabase(cNewFolder, lDBUri, True);

  FClient.ServiceRegister([TypeInfo(ILCSDatabase)],sicShared);  // <<==Error:  "LCSDatabase" interface or REST routing not supported by server
  FClient.Services[lDBUri].Get(lDbInterface);

What am i doing wrong?

Offline

#2 2012-09-07 09:07:21

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

Re: Opening a remote database through Client-server services

You need to be authenticated on the client side to access remotely to the service.

See sample code.

Offline

#3 2012-09-07 09:35:51

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: Opening a remote database through Client-server services

You mean running  THttpApiServer.AddUrlAuthorize() ?
Done that

Offline

#4 2012-09-07 09:56:19

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

Re: Opening a remote database through Client-server services

No, TSQLRestClientURI.SetUser() method. smile

Offline

#5 2012-09-07 10:07:45

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: Opening a remote database through Client-server services

But when creating the TSQLRestServer i have set HandleUserauthentication to false ...

Offline

#6 2012-09-07 11:43:14

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

Re: Opening a remote database through Client-server services

User authentication is mandatory for using services.

You have to set HandleUserauthentication = true, otherwise you won't be able to use remotely services.

This is mandatory for security reasons.
You can use hardcoded username and password for the communication, in your client code, if you do not need to handle user grant access at your application level.

Offline

#7 2012-09-07 11:51:30

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: Opening a remote database through Client-server services

aHa!

Offline

Board footer

Powered by FluxBB