Developer

Initializing an Online Store

Initialize an online OData store for online OData access.

Prerequisites

Define the back-end OData connections required by the application in the SAP Mobile Platform Server Management Cockpit or HANA Cloud Platform Mobile Services Cockpit. For detailed information see SAP Mobile Platform http://help.sap.com/mobile or SAP HANA Cloud Platform Mobile Platform https://help.hana.ondemand.com/hana_cloud_platform_mobile_services/frameset.htm.

Context

The ODataStore library interacts extensively with the OData service. One ODataStore instance interacts with one OData source: If a SAP Mobile Platform Server-hosted application is defined with two or more back-end URLs (whitelisted connections), a separate ODataStore instance is required for each. The ODataStore hides many of the complexities of interacting with the OData source, and internally uses the Microsoft OData parser.

Procedure

  1. Opening the Online Store requires configuring the HttpClient. The following configuration can handle Basic authentication and SAML authentication. Additionally, X-CSRF-Token handling is enabled and the connection id is sent automatically in each request:
    var client = new SAP.Net.Http.HttpClient(
       new System.Net.Http.HttpClientHandler() {
       Credentials = new System.Net.NetworkCredential( (string)registrationContext.BackendUserName,
                                                                                     (string)registrationContext.BackendPassword)
       }, true
    );
    client.DefaultRequestHeaders.TryAddWithoutValidation("X-SMP-APPCID", connectionId);
    client.DefaultRequestHeaders.TryAddWithoutValidation("X-SUP-APPCID", connectionId);
    client.ShouldHandleXcsrfToken = true;
    client.ShouldHandleSamlRequests = true;
    client.SamlFinishEndpoint = new UriBuilder(registrationContext.IsHttps ? "https" : "http",
       registrationContext.ServerHost,
       registrationContext.ServerPort, "/SAMLAuthLauncher").Uri;
    client.SamlFinishEndpointParameter = "finishEndpointParam";
    await SharedContext.Context.Store.OpenAsync(client);
    
  2. Create an online ODataStore. There are two overloaded constructors for the ODataStore:
    • Constructor 1:
      public ODataStore(string serviceUri, ODataStore.EntityFormat entityFormat = ODataStore.EntityFormat.XML);
       
         //The first parameter is the URI for the OData Service passed as a string
         //The second parameter is the entity format.  The default option is XML.  
         //Using JSON greatly reduces network traffic and is recommended.
         public enum EntityFormat
         {
             JSON = 0,
             XML = 1,
         }
       
         //Example:
         var store = new ODataStore("uri");
      
      
    • Constructor 2:
      public ODataStore(Uri serviceUri, ODataStore.EntityFormat entityFormat = ODataStore.EntityFormat.XML);
       
         //The first parameter is the URI for the OData Service passed as a System.Uri
         //The second parameter is the entity format.  The default option is XML.  
         //Using JSON greatly reduces network traffic and is recommended.
         public enum EntityFormat
         {
             JSON = 0,
             XML = 1,
         }
       
         //Example:
         var store = new ODataStore(new Uri("uri"), EntityFormat.JSON);