Salesforce

Web Services as a Database (Magic xpa 3.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

Web Services as a Database

Web services are sometimes used as a means to access data in large organizations, instead of using database clients. Magic xpa provides a native development paradigm to support data access via a Web service. Once having defined the data source as a Web Service data source, the developer can use the data source in native Magic programs. You can use the Web Service Data Source builder to help you create Web services on the provider side.

Note:

This feature is only available if you set the SpecialWebServiceDataSource flag to Y. Please note that this feature might be changed in future versions and will not maintain backward compatibility in future versions.

To use a Web Service as a database, you should first define the Web Service in the Composite Resource Repository as a WCF component. You need to add a declaration for each data source or even per each operation per data source. The endpoint URL is configurable at the level of the configuration files (in the WCFClientModules folder). For example: <endpoint address="http://localhost:8000/), which is external to Magic xpa.

When using the Web Service Data Source builder, an export file of the required WCF entries will be created for you, so you can simply import it to the application.

Best practices:

To improve performance, shared data, such as currencies, cities, and description tables, should be one of the following:

  • Fetched once in a while and kept in a local storage such as a Space database. In this case, all of the contexts will not need to use the Web Service database for the shared data.

  • Marked as Resident so that the engine will first fetch them. This way, they will not be fetched again each time they are used.

Any non-Local SQL database can be defined as a Web Service database using these properties:

At runtime, for Web Service data sources, the data will be automatically retrieved and updated by the Magic engine using Web Service calls to a Web Service provider. You do not need to write any code for this.

If you want to use Magic xpa as a provider, you can use the DataManipulate function, which will build the XML files (to be returned to the client), so that the development of the provider side is simple without the need to develop code that builds XML files. The provider program can be a simple program with one BLOB.

Note:

  • Make sure to use the same data source definition on the consumer and the provider.

  • Studio operations on a Web Service database, such as Get Definition and changes to tables, will be done on the real database (the Run as a Web Service Database property will be ignored and considered as False).

Class and Method Names

Runtime Behavior for Web Service Databases

  • Before the data source of this database is accessed (fetched), a read request will done to the Web service.

  • After a record of a data source of the database is created, updated or deleted (but before the update is committed), a Create, Update or Delete request is done to the Web service.

  • The data is sent using a SOAP protocol.

  • The data structure is XML.

Read

To read data, a Web Service data source can be used as a Main Source, Link Query, Link Write or Data control.

  • Main Source – When a fetch is done to a Web Service data source (defined in the task’s Main Source), a WCF request is done to the Web Service URL defined in the database of the data source and the data will be retrieved from the Web service to the Magic xpa engine according to the range criteria. If data already exists in the data source, the new data will be added (merged) to the existing data. The data will be stored (per context) in a temporary table (as defined in the Database settings). When the data source is closed (and is not opened in any other parent task) the data will be removed from the temporary database.

  • One-record Link Query and Link Write (with Locate on all the columns in the unique index) – When a Web Service data source is used in a Link Query or Link Write, a check is made to see if data already exists in the memory storage.

  • If the data does not exist, a WCF request is done to the Web Service URL defined in the data source and the data will be retrieved from the Web service to the Magic xpa engine according to the range/locate criteria.

  • If more than one record is retrieved, Magic xpa will show the first one (as in Link to other DBMS).

  • All of the data fetched in the link will be added to the memory storage of this data source. It will be cleared when the table is closed (as above).

  • Multiple-records Link Query and Link Write (without Locate on all the columns in the unique index) – Will fetch all the records according to the other locate criteria (similar to the Main Source). For such scenarios, the request XML will have an entry of ‘number of records’ with the value of 1, so that the provider will only return one record to Magic xpa. In this type of scenario, a Magic range on links is not supported.

  • Data control – Will fetch all the records according to the range criteria (similar to the Main Source).

Create

To create data, a Web Service data source can be used as a Main Source, Link Create or Link Write.

When a new record is created in a Web Service data source (either as a Main Source or links), before the record is updated to the temporary database (moving to the next record or closing the task), a WCF request is done to the Web Service URL defined in the database of the data source and the data will be sent to the Web service.

  • The Create operation is first executed on the Web service and only if this succeeds then an update is done to the temporary database.

  • The data is sent separately for each record. Bulk create/update operations are not supported.

  • After the Web service updates the data successfully to the database, if the record is returned from the Web service, then the memory table is updated according to the values returned from the Web service.

When the data source is closed (and is not opened in any other parent task), the data is removed from the temporary database.

Update

To update data, a Web Service data source can be used as a Main Source, Link Query and Link Write. The behavior is the same as the Create operation with the following differences:

  • Only the columns that were updated will be sent to the Web service.

  • If the required record does not exist, an error will be returned.

Delete

To delete data, a Web Service data source can be used as a Main Source. The behavior is the same as the Create operation.

Range and Locate

Ranges are defined in the XML request according to the range defined on the data source columns. The Magic Range and Locate is performed on the temporary storage in the Magic xpa server side after fetching the records from the Web service.

Logging

For Web Service data sources (Since version: 3.2a):

  • The logging definition used is the logging definition of the original database.

  • It is not possible to dynamically stop and start the logging for Web Service data sources.

Error Handling

When an error is returned from the Web Service provider (in the response XML), the behavior will be as if the error happened on the real database.

Exceptions

  • A Web service as a database is not supported for Browser Client tasks.

  • For Rich Client tasks, this functionality is implemented on the server side. It is only supported when the Magic xpa server is running on the Windows operating system.

  • Null values are not supported. For more information, see Null Value - SQL Considerations.

  • Paging of data (between the Web service and the Magic xpa engine) is not done automatically. You need to define ranges in your queries. In Rich Client tasks, once the data is read from the Web service to the Magic xpa engine, it will be sent to the clients in chunks (as current).

  • A Link Join operation cannot be used on a Web Service database.

  • The DataViewTo* and DB* functions are not supported, except for the DbName and DbReload functions.

  • Foreign keys are not supported for the Web Service database at runtime. If they are defined, they will be ignored. Foreign keys can still be defined in the Studio.

Since version: 3.2

Reference
Attachment 
Attachment