When a Multi-tenant application exposes Web Services, facilities must be implemented to ensure the Web Service logic runs in the context of the correct tenant.

In these situations, the web service must receive information that allows switching the context to the proper tenant, either by explicitly receiving information about the tenant or information about the end-user that made the request and inferring the tenant he belongs to.

Explicitly Sending Tenant Information

When the web service is called, it receives information about the tenant. In the example below the web service receives the company name.

The TenantId is then inferred based on the company name, and the TenantSwitch System Action is used to change the context on which the logic runs.

Finally the business logic is processed, only retrieving data belonging to the correct company.

Sending User Credentials

By receiving the end-user credentials and using the User_Login Action from the Users application, is also possible to change to context on which the web service logic runs.

The User_Login Action automatically binds the session to the correct tenant, making the rest of the logic run constrained to the tenant the end-user belongs to.

See Also

About Multi-Tenancy | TenantSwitch