You are not logged in.
Pages: 1
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
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
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
You wrongly used the TSQLRestServer.ServiceDefine. Should be:
aStockServer.ServiceDefine( TLegacyStockQuery, [ILegacyStockQuery]);
Source code (mORMot 1.18.3177, Delphi XE5):
Legacy-20161116.zip
Offline
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
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
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
Pages: 1