Skip to Content
Product Information
Author's profile photo Lana Turner

Guide to easily create and deploy an OData Service using our new Mobile Backend Generator

About the Mobile Backend Generator

If you haven’t heard already, there’s a brand-new way to create and deploy an OData service, using the Mobile Backend Generator. The Mobile Backend Generator is a set of tools included with SAP Web IDE that interacts with SAP Cloud Platform Mobile Services. These tools are now available to customers with the latest release of the Mobile Development Kit (MDK) on SAP Web IDE for trial or preview landscapes. You’ll need to create a trial account to use this new feature, if you don’t have one already.

This blog walks you through generating and deploying an OData service to the Neo or Cloud Foundry landscape. Even if you plan to deploy to Neo, you require a Cloud Foundry account as well.  Cloud Foundry provides the builder service for the Mobile Backend Generator.

About the MDK

MDK is a feature of SAP Cloud Platform Mobile Services. If you’re new to MDK and want to learn more about developing apps without having to do much coding, you might want to begin by going through this Learning Journey and these helpful videos.

Setting Up Your Environment

Ensure that the SAP Web IDE Full-Stack is enabled.

Select the box and under Take Action, select “Go to Service”.

Select the gear in the left menu (1) and select “Features” (2). Make sure that “Mobile Services App Development Tools V master” is On (3).

Select “Cloud Foundry” (1), verify that you have a builder installed (2) and that it is up to date. When the installation or update is complete, select “Save” (3). I missed this and wondered why I couldn’t continue!

Generating an OData Service

Select the “</>” symbol (1) to enter your workspace. Right-click your workspace folder, select “New” (2)  then “Project from Template.”(3)

Change the Category to “All categories” (1) and select “Mobile OData Service Project.” (2) Select “Next.” (3)

Provide a project name (1), then select “Next.” (2).

Provide a service app name (1) and the version (2). Here, for simplicity, I’m using a deployment target of Neo (3), “None” (4) as the authentication mode, and an in-memory database (5). If you wish to have test data generated, check “Use generated test data”(6).Select “Finish” (7) when done.  See Generating an OData Service for choices other than in-memory database.

You have the ability to view and edit these generation properties at any time by right clicking your project folder(1), select “Project”(2) then “Project Settings”(3).

Add a model to your project by importing a CSDL (Common Schema Definition Language) file that you’ve previously created. Right-click your project folder (1), select “Import” (2), then “File or Project.” (3)

When you see the import screen, browse to the location of your csdl.xml file (1), then select “OK”. (2)

Next, you’ll see a visual representation of your CSDL file. You can use our CSDL graphical modeling tool to create or modify an existing csdl.xml file.

You can create your own csdl.xml file if you don’t already have one. Right-click your project folder, (1)  and select “New” (2), then select “OData CSDL Document.” (3)

You can use either OData Version 2.0 or Version 4.0 (1). Please see Overview for OData versions to help determine what version is correct for you. Provide a schema namespace (2) and a namespace alias (3), then select “Create” (4). The file name is generated automatically from the schema namespace.

Double-click the csdl.xml file to use the graphic editor to graphically create your model. Remember to save your changes!

Right-click your csdl.xml file (1), select “Generate Mobile OData Service” (2) to generate the OData service.

The srv (service) folder now contains new files and folders. Right-click your srv folder (1),

select “Build”(2)(3) .

The target folder now contains an odata-service-version#.war file.

Deploying the Generated Service to Neo

Right-click your generated war file in the target folder (1) , select “Export.” (2) This saves the file locally.

Since you cannot deploy to Neo from Web IDE, move to the SAP Cloud Platform cockpit of your Neo landscape. Select “Tools” (1) from the top menu and select “SAP Cloud Platform Cockpit”. (2)

Once you’re in the cockpit, go to “Applications” (1) then “Java Applications,” (2) then select “Deploy Application”. (3)

Browse to the war file you exported (1) and enter an application name (2) (this is the name that will display in Neo). Select the runtime “Java EE 7 Web Profile TomEE 7.” (3) When done, select “Deploy.” (4)

When the deployment completes, select “Done”. Don’t start the service yet.

Select the service name.

Since this blog used the in-memory database and None as authentication method options, select “Start”. Otherwise, you’ll need to bind your database to your application.

Once the service starts, you see its URL in the Application URLs.

Select this link to access your OData service and make sure it works from a browser.

Deploying the Generated Service to Cloud Foundry

Even though I chose Neo as the deployment landscape, I’ve added the instructions to Cloud Foundry because they are simple!

You can deploy your application to Cloud Foundry from Web IDE. Right-click on your project folder (1) and select “Build” (2), then “Build.” (3)

Right-click on the srv folder (1), select “Run” (2), then “Run as Java Application” (3).

Once the app is deployed, you’ll see a URL just above the console.   You can test and debug your service within Web IDE.

Select the link to access your OData service and make sure it works from a browser.

Now you are ready to use your newly generated OData service by building a mobile app with SAP Cloud Platform SDK for iOS,  SAP Cloud Platform SDK for Android, MDK or SAP Mobile Cards!

I hope you enjoyed my first blog!

 

Assigned tags

      18 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jayakrishnan Chandramohan
      Jayakrishnan Chandramohan

      Hi,

      I didn't understand the below step. Where do i create my model or csdl.xml file? Is this blog have any parent blog in which i can refer this step? Please help me on this.

      "Add a model to your project by importing a CSDL (Common Schema Definition Language) file that you’ve previously created"

       

      Thank you,

      Regards,

      JK.

      Author's profile photo Lana Turner
      Lana Turner
      Blog Post Author

      Good day JK,

      This blog is not part of another blog.  This step assumes that you have a pre-existing csdl.xml file.

      The following step shows you how to create an csdl.xml file but doesn't get into the detail.  Sounds like something that we should blog about.  This is something we have discussed.  I will document the process.

      Lana

       

       

      Author's profile photo Anton Orlov
      Anton Orlov

      Hi Lana, congrats with your first blog! I find the article very inspiring.

      Does the method described allow to create oData services with creation/deletion functions and not only read?

      Regards, Anton

      Author's profile photo Martin Lacasse
      Martin Lacasse

      Hi Anton,

      The service we generate supports the full Create, Update, Delete operations without requiring any extra coding.  If you want to implement actions (OData V4) or Function Imports (OData V2), we would generate the stubs, but then you would have to code the business logic.

      Our generated code has extension points to add any custom logic outside of the generic CRUD service we generate.

      thanks

      Martin

      Author's profile photo Anton Orlov
      Anton Orlov

      Thanks for the answer, Martin! It definitely makes me even more interested in this tool. Meanwhile I have one more question if you don't mind.

      What's the reason why you call it "Mobile" backend generator? Are there any limitations which don't allow me to use this tool for my Fiori applications rather than mobile apps?

      Regards, Anton

      Author's profile photo Anton Orlov
      Anton Orlov

      Is anyone here?

      Author's profile photo Martin Grasshoff
      Martin Grasshoff

      The Mobile Backend (currently still called “Service generator”) generator ensures a quality of service to the OData services tailored for mobile consumption and use cases (especially the offline scenario).  Our tools are closely integrated with Mobile Services.  Nothing stops you from using these services in a UI5 app, but the CAP (Cloud App Programming Model) also allows to model/generate OData services with a much more tight integration to UI5 SDKs.  We are working on bridging the gap between the two products.

      And sorry for the late reply...it's TechEd time 😉

      Author's profile photo Anton Orlov
      Anton Orlov

      Thank you, Martin!

      Author's profile photo Lana Turner
      Lana Turner
      Blog Post Author

      Thanks for the nice comments Anton.  Makes me want to write more blogs! 🙂 Martin has provided the answer to your question.

      Author's profile photo Manjunatha Nagaraj
      Manjunatha Nagaraj

      I am getting error when I try to generate OData Service. Please see the attachment.

      The error is about destination not defined. And I see nothing in ‘srv’ folder.

      Please could you let me know what could be wrong? I did check that in CF, build is uptodate.

      Author's profile photo Lana Turner
      Lana Turner
      Blog Post Author

      My apologies, I didn't see this note. I assume that you have resolved this issue.  If not, let me know.  Thank you.

      Lana

       

      Author's profile photo Han Quan Lim
      Han Quan Lim

      Hello Lana, I am getting the same error too following the tutorial, may I know how this issue can be fixed? Is there any additional configuration that must be done?

      Author's profile photo Leonard Heilos
      Leonard Heilos

      Hi, seems like your Mobile Services destination is not configured properly or was deleted by accident. Try to create a new destination (or check existing) in SAP Cloud Platform Cockpit under Connectivity ... Destinations:

       

      Name: mobileservices
      Type: HTTP
      URL: <mobile-services admin url>
      ProxyType: Internet
      Authentication: AppToAppSSO

       

      Also add the following properties:

      WebIDEAdditionalData: build
      HTML5.ConnectionTimeoutInSeconds:20
      WebIDEUsage: svc_mgmt
      HTML5.SocketReadTimeoutInSeconds: 200
      WebIDEEnabled: true
      SkipSSOTokenGenerationWhenNoUser: true
      HandleRedirects: false

       

      The Mobile Services admin URL can be retrieved from the Mobile Services Cockpit (goto Services ... Mobile Services ... Go to Service) using Important Links ... Copy Admin API

      For hanatrial it looks like this: https://hcpms-dxxxxxxtrial.hanatrial.ondemand.com

      Author's profile photo Seyed Ismail
      Seyed Ismail

      Hi Leonard,

       

      Thanks for the hint. I tried it. With ApptoAppSSO, I am getting "not authorized" message. With Basic Authentication, I am prompted to enter username and password for  https://webidecp-XXXXXXXXXXtrial.dispatcher.hanatrial.ondemand.com/ but unsuccessful even after providing right credentials.

       

      Please help. Thank you in advance.

       

      Seyed Ismail.

      Author's profile photo saket amraotkar
      saket amraotkar

      Hi Manjunatha Nagaraj,

       

      There is no need of adding any destination, you have to make sure that you have enable

      Service: Mobile Services, users - Overview on your NEO environment, it should work for you.
      Do let me know if you faced any issue.
      Regards
      Saket Amraotkar
      Author's profile photo Matteo Prinetti
      Matteo Prinetti

      Hi Martin,

      Thanks for this very useful blog.

      2 Questions:

      a: With "normal" oData services we usually define the key to have a "real" meaning. For example a UserSetting Entity would have UserName as a key. With Hana we always get a internal ID Key (a Int64) - is there a way to keep to have for example UserName "MFRANK" as a key and not the Int64 ?

      b: when we update the Data Model (for example we change a Field Type or add another entity) - is there a way to have the App to change the Hana DB for us ? Actually If I change something I have to drop every table etc so they get created again.

      Thanks

      Author's profile photo Evan Ireland
      Evan Ireland

      Hi Matteo,

      Regarding your questions:

      (a) It is possible to configure a service (with some extra code in the ProviderSettings.init method) to disable automatic key generation, but we prefer that you use "surrogate" keys as the OData keys so that the SQL database can generate keys automatically. You can have non-key properties to hold business keys if that is desired.

      (b) The upcoming release will automatically add tables/columns assuming you have made backwards-compatible schema changes.

       

      Author's profile photo Dhanika Wickramaratne
      Dhanika Wickramaratne

      Hi All,

      When creating the Mobile OData Service Project, we have the option to select the database type.

      Instead of this, is it possible to connect to an on-premise SAP system.

      Lets say I need to fetch data from a Function Module in my SAP system and map the data to the model created. Is there any possibility like that?

       

      Thanks.