Skip to content

Service Initialization with the Dynamic API

DataService requires an implementation of the DataServiceProvider interface as a parameter to its constructor. This section uses an instance of OnlineODataProvider to interact with the service in an online fashion, which sends requests directly to the service provider. Offline usage requires the OfflineODataProvider.

// Create an instance of OnlineODataProvider
OnlineODataProvider provider = new OnlineODataProvider("EventService",
    SERVICE_URL, new OkHttpClient.Builder().build(), true);

// HttpHandler can also be set
// provider.getNetworkOptions().setHttpHandler(handler);

// Create an instance of DataService
DataService dataService = new DataService(provider);

// Disable data service version check
// Avoid error when OData provider returns version below V2.0
provider.getServiceOptions().setCheckVersion(false);

// Configuration
// Set OData trace options
provider.setTraceRequests(true);
provider.setTraceWithData(true);
provider.setPrettyTracing(true);

// Set Atom as the data format
// provider.getServiceOptions().setDataFormat(DataFormat.ATOM);
// Set JSON as the data format
provider.getServiceOptions().setDataFormat(DataFormat.JSON);

// If service does not support batch, turn off batch requests
// provider.getServiceOptions().setSupportsBatch(false);

// Allow HTTP verb tunneling over OData batch requests
provider.getNetworkOptions().setAllowTunneling(true);
// Disable compression
// provider.getNetworkOptions().setCompressResponses(false);
// Disable streamed downloads
// provider.getNetworkOptions().setStreamDownloads(false);
// Disable streamed uploads
// provider.getNetworkOptions().setStreamUploads(false);

// Ping server to check connection
dataService.pingServer();

// Get provider from service reference
provider = (OnlineODataProvider) dataService.getProvider();
// Create an instance of OnlineODataProvider
val provider = OnlineODataProvider("EventService",
    SERVICE_URL, OkHttpClient.Builder().build(), true)

// HttpHandler can also be set
// provider.networkOptions.httpHandler = handler

// Create an instance of DataService
val dataService = DataService(provider)

// Disable data service version check
// Avoid error when OData provider returns version below V2.0
provider.serviceOptions.checkVersion = false

// Configuration
// Set OData trace options
provider.traceRequests = true
provider.traceWithData = true
provider.prettyTracing = true

// Set Atom as the data format
// provider.serviceOptions.dataFormat = DataFormat.ATOM
// Set JSON as the data format
provider.serviceOptions.dataFormat = DataFormat.JSON

// If service does not support batch, turn off batch requests
// provider.serviceOptions.supportsBatch = false

// Allow HTTP verb tunneling over OData batch requests
provider.networkOptions.allowTunneling = true
// Disable compression
// provider.networkOptions.compressResponses = false
// Disable streamed downloads
// provider.networkOptions.streamDownloads = false
// Disable streamed uploads
// provider.networkOptions.streamUploads = false

// Ping server to check connection
dataService.pingServer();

// Get provider from service reference
provider = dataService.provider as OnlineODataProvider

Last update: August 12, 2020