Welcome! Log In Create A New Profile

Advanced

[WB25] Flexible REST Webservices Database Location

Posted by Mujahid 
[WB25] Flexible REST Webservices Database Location
November 22, 2021 01:28AM
Hi,

Is it possible to dynamically point the Database Location (HFSQL) for REST Webservices?
Customer A will send file to Database A
Customer B will send file to Database B

For example :

//Initializing POSData (server)

MyAdminName is ANSI string
MyAdminPassword is ANSI string
MyServerAndPort is ANSI string
MyDatabaseName is ANSI string
MyConnection is Connection

MyAdminName = "Admin"
MyServerAndPort = "123.123.123.80:4900"


MyDatabaseName = "POSData - " + "Company A"


// Connection to HFCSDatabase
MyConnection..User = NoSpace(MyAdminName)
MyConnection..Password = NoSpace(MyAdminPassword)
MyConnection..Database = NoSpace(MyDatabaseName)
MyConnection..Server = MyServerAndPort
MyConnection..Provider = hAccessHFClientServer
MyConnection..Access = hOReadWrite
MyConnection..CursorOptions = hServerCursor+hDynamicCursor+hOptimisticCursor
MyConnection..ExtendedInfo = "Read Databases from HF C/S"
MyConnection..CryptMethod = hCryptRC5_16


IF NOT HOpenConnection(MyConnection) THEN
Error("HOpenConnection: ","Unable to connect to "+MyServerAndPort,HErrorInfo(hErrFullDetails))
ELSE
// Assign the connection to all data files
HChangeConnection("*", MyConnection)
END


How to set the MyDatabaseName as above for REST Webservices?

Currently i only look that the REST Webservices only can set a default single database location at the Initializing of server.

Please advice. Thanks a lot.

Regards,
Mujahid
Re: [WB25] Flexible REST Webservices Database Location
November 22, 2021 04:34AM
Hi All,

I found one solution.

All file will included BusinessName.

At the FormatToFile Classes i place the DB connection.

PROCEDURE PRIVATE GLOBAL FormatToFile() : boolean

// The content of POST/PUT is a string containing JSON encoded in UTF-8.
sRecordContentInJSON is ANSI string = WebserviceParameter(paramBuffer)

clCompany is MCompany
// Loads the record content in the class instance. Depending on the case, we get:
// - At creation: the default record values.
// - On modification: the previous record values.
// Therefore, the proper value will be stored for all the non-exposed items and for all the items not transmitted by the consumer.
clCompany.FileToMemory()

// Read and validate.
Deserialize(clCompany, sRecordContentInJSON, psdJSON)
// HERE: Add the code to validate incoming data.


lp_DBConnection(clCompany.m_sBusinessName)

// Write on the file.
clCompany.MemoryToFile()

RESULT True


No need to add DB connection setting at Initializing (server)

The File from WD File terminal (Branches) will be send to Cloud server by each Company Database just using single REST Webservices.

So far it is work.

If you ave any suggestion please share. Thanks.

Regards,
Mujahid
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: