Technical Articles
Adding multiple OData services and syncing the metadata and annotation file using service manager in visual studio code.
In this blog post, I would like to explain about Service Manager in Visual Studio Code. Service Manager is a feature which is available in a Service Modeler. Normally we use Service Manager while working with services.
Features of Service Manager
- We can add OData service
- We can sync the metadata and annotation file.
Prerequisite:
Sap Fiori tools – Service Modeler extension should be enabled (or installed).
Let’s Start
First create the UI5 application in vscode. At the time of application creation, we can consume OData service by providing service url , so that service configuration will be done automatically in manifest and destination configuration in ui5.yaml file .
-
How to add multiple Services.
Step 1 :
We can open Service Manager as bellow.
From the File Explorer in your project, navigate to webapp->manifest.json
Right click on manifest file ->click on open Service Manager.
Step 2 :
Service Manager page will display as bellow .Later click on Add Service button.
Step 3 :
Provide full path of OData service (service URL).
Then enter client Username and Password.
Finally click on Add button. Now OData service is successfully added.
Step 4:
Data source configuration and model creation will be done automatically. We can check in manifest.json file. Also corresponding metadata.xml file will be created under local service.
dataSource configuration.
Model creation.
Metadata.xml file for corresponding added service
Step 5:
Configuring the destination (Proxy) in UI5.yaml file.
path: – Represents starting path means uri provided in manifest must start with this path .
url :- Represents source URL ex :- http://180.8.6:6098
Step 6:
We can bind the OData service to view or in controller with the help of model.
-
How to sync the metadata and annotation file.
Why we have to sync the metadata?
Suppose we have extended the OData service in backend by adding properties to entity type or created new entity set for existing OData service .At this point the metadata will get change. So in order to update the metadata.xml or annotation (if we are using external annotation or CDS) present in the ui5 application, we need to sync the OData service. Otherwise we have to update metadata.xml file manually.
Step 1:
Open service manager by right click on manifest file ->click on open Service Manager. Then click on sync button.
Step 2:
Provide client username and password.
Finally click on sync button. Metadata and annotation file will automatically get updated. We can check it in metadata.xml and annotation.xml file.
Conclusion
In this blog post, we have learnt about how to add multiple OData service and syncing metadata file. Service Manger is a good feature available in Visual Studio Code via Fiori Tools Extension Pack.
Hope this blog is very helpful ,thanks for reading.
Shivaraj
Hello,
Thanks a lot for this blog, I didn't know the existance of this tools.
You should update your blog, because, to have access to the Service Manager we have to do this :
How to launch Service Manager
webapp->manifest.json
Open Service Manager
Regards,
Joseph
Updated
Thanks
Shivaraj
Hi Shivaraj Gowda ,
Thanks for the very informative blog. In my requirement i need to add one third-party non sap service (Weather Info). In web ide development i simply used ajax call, but later i faced cors issue.
Could you please suggest me that how can i add the service here and how to consume it?
Thanks,
Jayakrishnan
Hi ,
Please go through below mentioned blog post for consume 3rd party service in webide. You need to configure the destination in order to over come CORS issue.
https://blogs.sap.com/2016/03/22/webide-how-to-consume-3-party-services-in-ui5-app/
How to add multiple destinations in ui5.yaml starting wih same prefix path "/sap" for /sap/opu/odata/sap/service1 main service and /sap/opu/odata/sap/service2 in ui5.yaml and in xsapp.json destination to consume it in SAP BAS?
Kindly help
So if you have two services starting with /sap and consuming these services from two different destinations then you need to make a couple of changes. You would need to change the routing to pickup a different URI exposed by the manifest.json and a different route to handle this in Cloud Foundry.
xs-app.json change;
manifest.json change;
As you can see, it means the URI for the datasource SAMPLEFLIGHT starts with ES5 and the route in xs-app.json will listen for this URI path and using regex, use the first group found i.e. /sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/ with your destination ES5.