Skip to content

Creating your first app with ODataOnlineCore Framework

Create proxy classes for your OData service

Have Java JDK or JRE installed on your machine and global variable JAVA_HOME set in your .bash_profile. You can set it like this:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home* 

Make sure to alter the path according to your java version and restart your terminal to apply these changes. First navigate to your SDK installation path/NativeSDK/ODataFramework/iOS/tools/proxy-generator-mobile/bin. Download the metadata of your service you intend to use in your application. You should name your metadata file, so it can identify your service, but try to make it short, like "Northwind.xml". Add executability permission to all scripts in the directory: chmod Run the following script like this: Your_metadata_file
Your proxy classes were generated at ../genfiles/oc*.

Assemble your project

Step one directory up from the location of the previous script, then navigate to genfiles/oc. Here you need 3 files added in your project: Your package name.h, Your package name.i and Your package name.m. Open your .xcworkspace file in your project directory and add the files above. Open Your package name.h and add the following line to import the SODataV4 runtime header:

#import "SODataV4_runtime.h"

Now your project should compile. If you intend to communicate with a server not supporting TLS v1.2 or newer protocol (in most cases this is an only HTTP instead of HTTPS server), you should add exception domains under your App Transport Security Settings in your Info.plist file. These exception domains will be allowed to communicate with, using HTTP protocol. The content of your Info.plist should include a dictionary like below:


Write some code

Add a new class to your project which will handle the objects necessary for representing your OData V4 requests and entities. The following lines are needed to start some simple requests:

// You need the header of proxy classes included:
#import "Your_package_name.h"
// The following property will be the representation of your service:
@property (nonatomic, strong) Your_service_name* service;
// Initialize your HttpConversationManager that will handle the requests. If you want to use authentication, you will also need a CommonAuthenticationConfigurator object.
HttpConversationManager* manager = [[HttpConversationManager alloc] init];
// The Online OData provider needs a handler object with the previous conversation manager.
SODataV4_HttpConversationHandler* httpHandler = [[SODataV4_HttpConversationHandler alloc] initWithManager:manager];
SODataV4_OnlineODataProvider* provider = [SODataV4_OnlineODataProvider new:\@"Give it some name" :\@"URL of your OData service" :httpHandler];
// Finally, the service object.
self.service = [Your_service_name new:provider];
//Choose an entity set object you want to get from your service. The available classes can be found in Your_package_name.h.
YourEntityList* EntityList = [self.service getYourEntityList];
NSLog(\@"%@", [EntityList toString]);
// Batch requests can be created like this:
// Create your queries
SODataV4_DataQuery* queryYourEntityList1 = [[[[SODataV4_DataQuery new] 
         select:\@[[YourEntity1 YourEntity1ID],[YourEntity1 SomeProperty1],[YourEntity1 SomeProperty2]]] 
         from:[Your_ServiceMetadata_EntitySets YourEntitySet]] 
         filter:[[[YourEntity1 YourEntity1ID] 
         equal:((SODataV4_DataValue*)((NSObject*)[SODataV4_StringValue of:\@"FilterForThis1"]))] 
         or:[[YourEntity1 YourEntity1ID] 
         equal:((SODataV4_DataValue*)((NSObject*)[SODataV4_StringValue of:\@"FilterForThisToo1"]))]]]; 

 SODataV4_DataQuery* queryYourEntityList2 = [[[[SODataV4_DataQuery new] 
         select:\@[[YourEntity2 YourEntity2ID],[YourEntity2 SomeProperty3],[YourEntity2 SomeProperty4]]] 
         from:[Your_ServiceMetadata_EntitySets YourEntitySet]] 
         filter:[[[YourEntity2 YourEntity2ID] 
         equal:((SODataV4_DataValue*)((NSObject*)[SODataV4_StringValue of:\@"FilterForThis2"]))] 
         or:[[YourEntity2 YourEntity2ID] 
         equal:((SODataV4_DataValue*)((NSObject*)[SODataV4_StringValue of:\@"FilterForThisToo2"]))]]];
// Create the batch request
SODataV4_RequestBatch* batch = [SODataV4_RequestBatch new];
[batch addQuery:queryYourEntityList1];
[batch addQuery:queryYourEntityList2];
// Process the batch request
[self.service processBatch:batch];
// You can get the result of your queries like this
SODataV4_QueryResult* result1 = [batch getQueryResult:queryYourEntityList1];
SODataV4_QueryResult* result2 = [batch getQueryResult:queryYourEntityList2];
// You can print the result. The type of *result1.result* is based on what kind of request you have sent. In this case, it was a read type.
NSLog(\@"%@", [result1.result toString]);
NSLog(\@"%@", [result2.result toString]);

You can also find useful content under your proxy generator directory/examples/oc.