cancel
Showing results for 
Search instead for 
Did you mean: 

No Data on Northwind OData service

former_member188632
Active Contributor
0 Kudos

Hello All,

I am trying to use OData model and getting data from Northwind Odata service. I tried a number of examples here, but I am getting NO DATA message when I am running the application. I referred to code sample from different SCN threads, but I am not able to get data in my table. Can anyone help me?

When I checked in Chrome console, I am getting error that says - Failed to load resource: the server responded with a status of 501 (Not Implemented) & XMLHttpRequest cannot load http://services.odata.org/Northwind/Northwind.svc/$metadata. Invalid HTTP status code 501

Following is my code:

var uri = "http/services.odata.org/Northwind/Northwind.svc"; // local proxy for cross-domain access 

  // create OData model from URL 

  var oModel = new sap.ui.model.odata.ODataModel(uri, true);  

  sap.ui.getCore().setModel(oModel); 

          

  var oTable = new sap.ui.table.Table({ // create Table UI  

  columns : [  

   {label: "ID", template: "SupplierID"},    

   {label: "Company Name", template: "CompanyName", sortProperty:"CompanyName" }, 

   {label: "Contact Name", template: "ContactName", sortProperty:"ContactName"},    

   {label: "Contact Title", template: "ContactTitle", sortProperty:"ContactTitle" }, 

   {label: "City", template: "City", sortProperty:"City"},    

   {label: "Country", template: "Country", sortProperty:"Country" }, 

  ] 

  }); 

      

  var f1 = new  sap.ui.model.odata.Filter('Country', [{operator:"BT",value1:"S", value2:"V"}]); 

  var f2 = new  sap.ui.model.odata.Filter('City', [ 

      {operator:"EndsWith",value1:"r"}, 

      {operator:"EndsWith",value1:"o"}, 

      {operator:"EndsWith",value1:"n"}], false); 

  oTable.bindRows({path: "/Suppliers", 

     parameters: { select: 'SupplierID, CompanyName, ContactName, ContactTitle, City, Country' },  

     filters: [f1, f2]}); 

  oTable.placeAt("content");

Thanks for all the help!

Ameya

Accepted Solutions (1)

Accepted Solutions (1)

ChandraMahajan
Active Contributor
0 Kudos
former_member188632
Active Contributor
0 Kudos

Hi Chandrashekhar,

Yes, it is working with Ajax call. The question is, why only with Ajax and why not the usual way? What difference does Ajax calls makes that fetches data while the usual way does not? Is this because of callign the northwind webservice or any other service issue?

Best Regards,

Ameya

former_member182862
Active Contributor
0 Kudos

HI Ameya

The main issue is that you are using a oData model and this service is not providing oData. I modified Chandra's jsbin to show how we are using JSONModel to fetch data.

Example

-D

former_member188632
Active Contributor
0 Kudos

Hi Dennis,

Alright! So had this service enabled to provide OData, my code should have worked, correct? Also, if a service is not providing OData, fetching data with JSONModel and Ajax should be the preffered choice?

I can see that you are not making any Ajax calls to fetch the data. So basically, JSONModel is all I need in this case? If yes, then why make Ajax call? Parond me for asking multiple questions. I am just trying to get my understanding clear.

Thanks a lot for calrifying on this!

Best Regards,

Ameya

former_member182862
Active Contributor
0 Kudos

The part of your code on model will work if the service is oData based (I am not sure about the rest of the code)

Since SAPUI5 has provided JSONModel, I do not advocate using Ajax.

Thanks

-D

former_member188632
Active Contributor
0 Kudos

Hi Dennis,

Thank you very much for your response! I think I got the answer I was looking for. I will not try this code with service that provides OData. Hopefully, I will be able to work that out as well!

Best Regards,

Ameya

ChandraMahajan
Active Contributor
0 Kudos

As Sakthivel mentioned the main issue is due to CORS and there are various ways to solve it. either running application by disabling SOP in chrome (javascript - Disable same origin policy in Chrome - Stack Overflow) or ways mentioned in this blog

Also please note that Northwind service is OData based. we can get response in json format by using $format=json

Regards,

Chandra

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ameya,

This issue is no where related to the service & the service provides oData. As you don't proxy the request it ends up in CORS issue. So a HTTP OPTIONS request is triggered which ends up giving 501(Not implemented) error. An working example using oData model.

JS Bin - Collaborative JavaScript Debugging

I've used https://cors-anywhere.herokuapp.com/ to resolve the cors issue, but this is just for testing & not to be used in productive code.

Regards

Sakthivel

former_member188632
Active Contributor
0 Kudos

Hi Sakthivel,

I tried using proxy as well. Here is the code that I used earlier.

var uri = "http://services.odata.org/Northwind/Northwind.svc"; // local proxy for cross-domain access 

  // create OData model from URL 

var oModel = new sap.ui.model.odata.ODataModel(uri, true);

I agree this can be a proxy issue though! In that case, above code did not really proxy the service, correct?

Ameya

former_member182862
Active Contributor
0 Kudos

I stand corrected. It is oData based. I am not aware of this.

You should stick to odata model as Sakthivel has suggested.

Thanks

-D

former_member188632
Active Contributor
0 Kudos

Hi Sakthivel,

Sorry I posted the wrong code, I tried using following code as well.

var uri = "/proxy/http/services.odata.org/Northwind/Northwind.svc";

I have defined organization proxy settings in Prerefences > network >proxy.

Any idea why this too did not work? What approach should be followed for Productive Systems?

Thanks again for giving dorection to this question.

Best Regards,

Ameya

Former Member
0 Kudos

It's just not about setting up the proxy. In UI5, they handle this by implementing a SimpleProxyServlet which you can find in web.xml if you've created your applications through eclipse using UI5 plugin. Even this is only for testing purpose

https://help.sap.com/saphelp_nw74/helpdata/en/2d/3f5fb63a2f4090942375df80abc39f/content.htm

I'm not aware of how to avoid CORS issues in productive code as we usually have all our services in the same domain.

Regards

Sakthivel