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
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.
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
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
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
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
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