Skip to Content
0

$metadata 404 (Not Found) when hosting SAPUI5 app

Oct 20, 2016 at 10:53 AM

910

avatar image

Dear Gurus

I have been developing SAPUI5 app that connects to WCF data service written in C# and there was no problem in the development process till i started to host the SAPUI5 app on my local IIS i started to get the following error in chrome developer tools $metadata 404 (Not Found) whenever i tried to connect to the service

While in eclipse the code runs with no errors

Can anybody guide me how to solve this issue

Thanks in advance

hosted.jpg (112.1 kB)
local.jpg (119.1 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
RA Eijpe
Oct 21, 2016 at 05:23 PM
0

You now overcome in the situation of Browser security restrictions. Your entry point of the UI5 application is different of the end-point of your odata service. If the Odata service and UI5 application runs on the same IIS server and port you don't need to specify the server and port in your ODataModel.

var oModel = new sap.ui.model.odata.ODataModel("/MIKMOWCFDataService.svc/");

If they are running in to different servers/port combinations, you should make the OData service Cross-Domain enabled by adding some header fields like

Access-Control-Allow-Origin: http/my.iis.server.domain
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods: GET, POST PUT, DELETE, OPTIONS
Access-Control-Allow-Credentials: true

Search for 'How to enable CORS in Odata .NET service?' on the internet will give you they answer.

Share
10 |10000 characters needed characters left characters exceeded
Jamie Cawley
Oct 20, 2016 at 12:33 PM
1

In eclipse you are probably using a proxy servlet to make the call to the backend, which is used to prevent browser security preventions. When running in iis you would have to adjust the path to the backend so it is directly connecting to it, which may cause browser security issues depending on where the service exists, or use some other proxy software.

Regards,

Jamie

SAP - Technology RIG

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Dear Jamie Cawley

Thanks for your fast reply

I used the below code to connect to the service

	onInit: function() {
		var oModel = new sap.ui.model.odata.ODataModel("proxy/http/mikmo.mylocalhost.com/MIKMOWCFDataService.svc/");
		oModel.oHeaders = {
				"DataServiceVersion": "2.0",
				"MaxDataServiceVersion": "2.0"
		}
		sap.ui.getCore().setModel(oModel,"groups");
	}

I have hosted my WCF data service on local IIS with the domain name mikmo.mylocalhost.com and port 80

I used the built in proxy to bypass CORS is this good enough or do i need to follow different approach

0
Jamie Cawley
Oct 20, 2016 at 01:33 PM
1

To run the app in iis you would have to set the model to

sap.ui.model.odata.ODataModel("http://mikmo.mylocalhost...

Regards,

Jamie

SAP - Technology RIG

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Dear Jamie Cawley

After changing the model from sap.ui.model.odata.ODataModel("proxy/http/mikmo.mylocalhost.com

to sap.ui.model.odata.ODataModel("http://mikmo.mylocalhost...

i got the following error

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:7575' is therefore not allowed access. The response had HTTP status code 501.

Any help would be much appreciated

0
Jamie Cawley
Oct 24, 2016 at 01:48 PM
1

You have to use the same domain for both the web page and the data source, http://mikmo.mylocalhost, or you can disable cors security checks in your browser.

Regards,

Jamie

SAP - Technology RIG

Share
10 |10000 characters needed characters left characters exceeded
Nelson Kharat Jun 25 at 02:25 PM
0

Hi,

am trying to fetch table from the Products from services.odata in my SAP UI5. I tried but I am not able to display the data in it. Although I am getting rows, but with no data.

when I try to F12 , I see that $metadata is not found. Please help with the below coding. Thanks in advance.

onInit: function() {
//Create a Model

var oModel = new sap.ui.model.odata.v2.ODataModel(‘proxy/http/services.odata.org/OData/OData.svc/’);

var oTable = sap.ui.getCore().byId(‘TAB1’);

//get Model for table
oTable.setModel(oModel);
oTable.bindRows(“/Products”);

Share
10 |10000 characters needed characters left characters exceeded