#1 2016-11-14 20:26:30

leus
Member
Registered: 2012-09-05
Posts: 79

Request: FireDAC / AnyDAC legacy server Sample

I've been trying to make this work:

https://tamingthemormot.wordpress.com/2 … databases/

I managed to get it compiled (after a few changes) and kind of working. I only get error 400, bad request, for any requests I make.

Can anybody make this work with an up-to-date mORMot version and share the modifications needed?

Last edited by leus (2016-11-14 20:26:41)

Offline

#2 2016-11-15 03:41:04

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: Request: FireDAC / AnyDAC legacy server Sample

You need to add DriverLink for FireDAC.
Try this:

procedure StartServer;
var
  aDriverLink   : TFDPhysIBDriverLink;
  aDbConnection : TSQLDBConnectionPropertiesThreadSafe;
  aStockServer  : TSQLRestServerFullMemory;
  aHTTPServer   : TSQLHttpServer;
begin
  aDriverLink := TFDPhysIBDriverLink.Create(nil);
  aDriverLink.VendorLib := 'fbclient.dll';
  aDbConnection := TSQLDBFireDACConnectionProperties.Create( 'IB?Server=localhost;Port=3050', 'DBNAME', 'SYSDBA', 'masterkey' );
  aStockServer  := TSQLRestServerFullMemory.Create([]);
  try
    aStockServer.ServiceDefine( TLegacyStockQuery.Create( aDbConnection ), [ILegacyStockQuery]);
    aHTTPServer := TSQLHttpServer.Create( DEFAULT_HTTP_PORT, [aStockServer] );
    try
      ...
    finally
      aHTTPServer.Free;
    end;
  finally
    aStockServer.Free;
  end;
end; 

Offline

#3 2016-11-15 12:31:01

leus
Member
Registered: 2012-09-05
Posts: 79

Re: Request: FireDAC / AnyDAC legacy server Sample

Thank you, I have modified my test. But I don't even get to the point the connection to the database is made; the HTTP request never get to the exposed method (it's always "400", "Bad Request".) I don't even know how to debug it, i.e., where to put a breakpoint.

Offline

#4 2016-11-16 03:31:41

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: Request: FireDAC / AnyDAC legacy server Sample

You wrongly used the TSQLRestServer.ServiceDefine. Should be:

aStockServer.ServiceDefine( TLegacyStockQuery, [ILegacyStockQuery]);

Source code (mORMot 1.18.3177, Delphi XE5):
Legacy-20161116.zip

Offline

#5 2016-11-17 02:30:57

leus
Member
Registered: 2012-09-05
Posts: 79

Re: Request: FireDAC / AnyDAC legacy server Sample

Thank you!

It works, but I don't know if I'm understanding this correctly:

private
    class var fDbConnection: TSQLDBConnectionProperties;
  public
    class procedure Init(const aProps: TSQLDBConnectionProperties);
    constructor Create(const aProps: TSQLDBConnectionProperties); overload;

How does this `class var` variable works in the context of the http server? Is it thread safe?

Offline

#6 2016-11-17 02:42:34

leus
Member
Registered: 2012-09-05
Posts: 79

Re: Request: FireDAC / AnyDAC legacy server Sample

After some time bashing at it - my object is called "TFactura." I'm using AnyDAC instead of FireDAC and it still works. This is not using a class var but an instance variable. Can anybody confirm which way is better, and why?

procedure StartServer(aDbURI: RawUTF8);
var
  aDbConnection: TSQLDBConnectionProperties;
  aStockServer: TSQLRestServerFullMemory;
  aHTTPServer: TSQLHttpServer;
begin
  aDbConnection := TSQLDBFireDACConnectionProperties.Create(aDbURI, 'mydb',
    'myusr', 'mypasswd');
  aStockServer := TSQLRestServerFullMemory.CreateWithOwnModel([], False,
    DEFAULT_SERVER_ROOT);
  try
    aStockServer.ServiceDefine(TFacturaQuery.Create(aDbConnection),
      [IFacturaQuery]);
    aHTTPServer := TSQLHttpServer.Create(DEFAULT_HTTP_PORT, [aStockServer], '+',
      useHttpSocket);
    try
      aHTTPServer.AccessControlAllowOrigin := '*';
      // allow cross-site AJAX queries
      writeln('Background server is running.'#10);
      writeln('Cross-Platform wrappers are available at ', DEFAULT_HTTP_PORT,
        '/', DEFAULT_SERVER_ROOT);
      write('Press [Enter] to close the server.');
      readln;
    finally
      aHTTPServer.Free;
    end;
  finally
    aStockServer.Free;
  end;
end;

Last edited by leus (2016-11-17 02:43:48)

Offline

#7 2016-11-17 03:56:14

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: Request: FireDAC / AnyDAC legacy server Sample

It depends on service instance lifetime. There are several modes: sicSingle/sicShared/sicPerUser and etc.

See "16.4.3. Instances life time implementation":
http://synopse.info/files/html/Synopse% … ml#TITL_92

In your implementation only sicShared may be used.

Offline

Board footer

Powered by FluxBB