Xdata Server with tAureliusConnection

Hi, I want to create a XDATA Server for Rest Services + Database-Server for our WEB-Application.

The Server and also registered servicecontract are working but I cannot get a tXDataWebConnection to load the entities.

This is my code for creating Serverside components:

procedure tMainForm.Initialize_Server_Components();
begin
	if not assigned(fConnectionFactory) then begin
        fConnectionFactory := TDBConnectionFactory.Create(
            function: IDBConnection
            var
                MyDataModule: tDataModuleEDB;
            begin
                MyDataModule := tDataModuleEDB.Create(nil);
			    result:=myDataModule.mcpAureliusConnection.CreateConnection;
//                Result :=  TElevateDBConnectionAdapter.Create(MyDataModule.mcpDatabase, MyDataModule);
            end
        );
    end;

	if not assigned(fConnectionPool) then begin
        fConnectionPool := TDBConnectionPool.Create(
            50, // maximum of 50 connections available in the pool
            // Define a number that best fits your needs
            fConnectionFactory
        );
    end;

	if not assigned(fXDataModule) then begin
		fXDataModule := TXDataServerModule.Create('http://+:2002', fConnectionPool);
	end;

	if not assigned(fServer) then begin
        fServer := THttpSysServer.Create;
        fServer.AddModule(fXDataModule);
    end;

end;

The tDataModuleEDB has only 3 components:
ElevateDatabaseSession: tedbsession;
mcpDatabase: tEDBDatabase;
mcpAreliusConnection: tAureliusConnection;

What I'm doing wrong?

What is the problem you get, which error message, at what line of code?
Are you able to access the same endpoints from a regular VCL application?

I don't have any errors - but I cannot get the entitiies in Web Application selected.
The WEB-Application itself (in designtime) does not show the database-tables

Well that is too few information to know what's going on.
If the problem happens in a web application, try to inspect the network requests in the Network tab in developer tools to have a better idea of what's going on - if the app is requesting the entity to the server, if yes, if there is some error in the request, etc.

I have send you this projects source via mail.

I haven't received it.

I had send it to supportcenter... but now you should receive a private message here with the attachment.

1 Like

Thank you for the project, but I'm not sure what I can do with it. It uses ElevateDB so I can't compile it in dev machine. Migrating to SQLite would make it easier.

But more importantly, the server app doesn't have much, where is the Web App that you claim it's failing? And before that, I gave several hints, have you checked it:

Other than this, a small error I got was this:

procedure TmcpConnectService.AfterConstruction;
begin
    inherited;
    fDB:=TEDBDatabase(TXDataOperationContext.Current.Connection);
end;

Such code is simply wrong, but you did it right in just another class:

procedure TmcpService.AfterConstruction;
var
	vtmp:string;
begin
    inherited;
    fConnection:=TXDataOperationContext.Current.Connection;
    fDB:=(fConnection as IDBConnectionAdapter).AdaptedConnection as tEDBDatabase;
    if assigned(fDB) then begin
        vtmp:=fDB.EngineVersion;
    end;
end;

Hi Wagner,

Thanks for all your tips and info! I tested two scenarios to see how to access the tEDBDatabase in the current context, and the successful approach was within TmcpService.

In general, accessing server-side functionalities and services (including database access) works fine.

What I need right now, however, is the ability to access database tables from a web app. In the current version, the tAureliusConnection does not automatically publish the database tables as entities. I believe that's the main challenge we're facing at the moment.

I don't see any entity class declared in your server application, so no entities will be published via XData server.

You have to add Aurelius entity classes mapped to tables to your app so they get published.

Reference:

https://doc.tmssoftware.com/biz/xdata/guide/aurelius.html#overview-of-aurelius-crud-endpoints

Hi Wagner,

I hadn’t declared any entities in code because I assumed Aurelius would handle that automatically. Now, we’ll switch to manual entity declaration or, ideally, handle data loading and saving from the web app through service instances.

Aurelius can automatically import the tables from your database and generate the entity classes for you. But then it's up to you to add them to your application.

The full process is described here:

1 Like