Description
Sets the PowerServer root URL (the Web API URL) for the installable cloud application.
This function is only effective in the installable cloud app deployed with PowerServer.
Applies to
Syntax
applicationname.SetPowerServerURL ( string asurl )
Argument |
Description |
---|---|
applicationname |
The name of the application object for which you want to set the Web API URL. |
asurl |
The new Web API URL you want to set, in the format: scheme://host[:port][/path], scheme can be lowercase "http" or "https", for example, https://www.example.com/salesapi. |
Usage
After you set the URL via SetPowerServerURL, you must manually create the session via BeginSession, which means the "Dynamic session parameters" option in the Application property dialog must be selected.
And after the session is created via BeginSession, the URL cannot be changed by SetPowerServerURL anymore unless the application is re-started, otherwise, SetPowerServerURL will return -1.
Return value
Integer. Returns 0 if it succeeds. Returns null if any argument’s value is null.
Returns -1 if any of the following happens:
-
The "Dynamic session parameters" option in the Application property dialog is not selected.
-
URL is not in a valid format.
-
the session has already been created manually via BeginSession.
-
the current application is not an installable cloud app deployed with PowerServer.
Examples
This example shows a common use case of the SetPowerServerURL function.
String strURL strURL = string("https://www.example.com/salesapi") GetApplication().SetPowerServerURL(strURL) //Creates the session manually GetApplication().BeginSession()
The following example shows how to use the SetPowerServerURL function to switch to the backup server, when the primary Web API server is not working, and after the end user restarts the application they can continue using the application (thereby indirectly implementing the server failover functionality).
String ls_new_url Blob lb_has_error Try GetApplication().BeginSession() Catch (runtimeerror er) // BeginSession failed if the primary server is down. lb_has_error = true Messagebox("BeginSession Failed", "It will try another service.") End Try If lb_has_error Then // It will try the backup server. // Change to the backup Web API URL. ls_new_url = "https://www.example.com/salesapibackup" GetApplication().SetPowerServerURL(ls_new_url) GetApplication().BeginSession() End If
See also