Skip to Content

$metadata 404 (Not Found) when hosting SAPUI5 app

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)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Oct 21, 2016 at 05:23 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 20, 2016 at 12:33 PM

    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

    Add comment
    10|10000 characters needed 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

  • Oct 20, 2016 at 01:33 PM

    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

    Add comment
    10|10000 characters needed 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

  • Oct 24, 2016 at 01:48 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 25 at 02:25 PM

    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”);

    Add comment
    10|10000 characters needed characters exceeded