Skip to content

Service Initialization

In order to communicate with the OData Service, instantiate an instance of the generated service class based on the metadata document. The constructor of the service class requires an implementation of the DataServiceProvider interface as a parameter. This implementation can be an instance of OnlineODataProvider or OfflineODataProvider.

Note

The name of the generated service class is specified using an argument during proxy class generation. If none is provided, it defaults to the name of the entity container in the service metadata document.

```java

OnlineODataProvider provider; ESPMService espmService;

if (configurationData.loadData()) { // Form the OData service URL to interact with OData service // Service URL points to the Cloud Platform Mobile Service // It is obtained from ConfigurationData loaded via ConfigurationLoader String serviceUrl = configurationData.getServiceUrl();

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// CONNECTION_ID_ESPMSERVICE is the destination of the Mobile Application representing the OData Service
// Instantiate an instance of OnlineODataProvider using the OKHttpClient used for authentication
provider = new OnlineODataProvider("SAPService", serviceUrl + CONNECTION_ID_ESPMSERVICE);
provider.getNetworkOptions().setHttpHandler(new OKHttpHandler(ClientProvider.get()));

// Turn off OData version checking
provider.getServiceOptions().setCheckVersion(false);

// Enable type information to be sent with requests
provider.getServiceOptions().setRequiresType(true);

// Disable caching of metadata i.e. metadata must be read on each start up
provider.getServiceOptions().setCacheMetadata(false);

espmService = new ESPMService(provider);

} ```

val provider:OnlineODataProvider? = null
val espmService:ESPMService? = null

if (configurationData.loadData()) {
    // Form the OData service URL to interact with OData service
    // Service URL points to the Cloud Platform Mobile Service
    // It is obtained from ConfigurationData loaded via ConfigurationLoader
    val serviceUrl = configurationData.serviceUrl

    // CONNECTION_ID_ESPMSERVICE is the destination of the Mobile Application representing the OData Service
    // Instantiate an instance of OnlineODataProvider using the OKHttpClient used for authentication
    provider = OnlineODataProvider("SAPService", serviceUrl + CONNECTION_ID_ESPMCONTAINER)
    provider!!.networkOptions.httpHandler = OKHttpHandler(ClientProvider.get())

    // Turn off OData version checking
    provider!!.serviceOptions.checkVersion = false

    // Enable type information to be sent with requests
    provider!!.serviceOptions.requiresType = true

    // Disable caching of metadata i.e. metadata must be read on each start up
    provider!!.serviceOptions.cacheMetadata = false

    espmService = ESPMService(provider!!)
}

Last update: August 12, 2020