cancel
Showing results for 
Search instead for 
Did you mean: 

Expected 'OData-Version' header with value '4.0' but received value 'null' in response

0 Kudos
3,404

Hi

I'm trying to use V4 OData Model for the first time in my app. I'm using CDATA API server to serve the ODATA. I can see the network requests for fetching the metadata and even the entity data are running succesfully.

I can even see the OData-Version value "V4" in Response-Headers.

But, the data in the binded table is not updating and I'm getting this error in console:

Failed to get contexts for http://localhost:8989/api.rsc/treeNodes with start index 0 and length 10 - Error: Expected 'OData-Version' header with value '4.0' but received value 'null' in response for http://localhost:8989/api.rsc/treeNodes?$select=displayName,id&$skip=0&$top=10
    at R.doCheckVersionHeader (https://openui5.netweaver.ondemand.com/resources/sap/ui/core/library-preload.js:3564:314)

Here's the metadata of my service:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
  <edmx:DataServices>
    <Schema Namespace="CData" xmlns="http://docs.oasis-open.org/odata/ns/edm">
      <EntityType Name="loggingNodes">
        <Key>
          <PropertyRef Name="id" />
        </Key>
	<Property Name="serverId" Type="Edm.Int32" Nullable="false"/>
	<Property Name="opcNodeId" Type="Edm.String" Nullable="false" MaxLength="2147483647" />
	<Property Name="displayName" Type="Edm.String" Nullable="false" MaxLength="2147483647" />
	<Property Name="queueSize" Type="Edm.Int32" Nullable="false"/>
	<Property Name="nodeId" Type="Edm.Int32" Nullable="false"/>
	<Property Name="dataChangeTrigger" Type="Edm.Decimal" Nullable="false"/>
	<Property Name="deadbandValue" Type="Edm.Double" Nullable="false"/>
	<Property Name="id" Type="Edm.Int32" Nullable="false"/>
	<Property Name="publishingInterval" Type="Edm.Int32" Nullable="false"/>
	<Property Name="samplingInterval" Type="Edm.Int32" Nullable="false"/>
	<Property Name="discardOldest" Type="Edm.Int32" Nullable="false"/>
	<Property Name="deadbandType" Type="Edm.Int32" Nullable="false"/>
      </EntityType>
      <EntityType Name="treeNodes">
        <Key>
          <PropertyRef Name="id" />
        </Key>
	<Property Name="type" Type="Edm.String" Nullable="false" MaxLength="2147483647" />
	<Property Name="opcNodeId" Type="Edm.String" Nullable="false" MaxLength="2147483647" />
	<Property Name="parentId" Type="Edm.Int32" Nullable="false"/>
	<Property Name="displayName" Type="Edm.String" Nullable="false" MaxLength="2147483647" />
	<Property Name="serverId" Type="Edm.Int32" Nullable="false"/>
	<Property Name="id" Type="Edm.Int32" Nullable="false"/>
      </EntityType>
      <EntityContainer Name="CData">
        <EntitySet Name="loggingNodes" EntityType="CData.loggingNodes" />
        <EntitySet Name="treeNodes" EntityType="CData.treeNodes" />
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

I'm getting the same error while trying to access either of the entitysets.

Here's the response-headers that I'm getting:

Access-Control-Allow-Origin: 
https://webidetesting9762247-p1940161775trial.dispatcher.hanatrial.ondemand.com
Cache-Control: 
private
Content-Type: 
application/json;charset=utf-8
Date: 
Fri, 03 Aug 2018 10:47:24 GMT
OData-Version: 
4.0
Server: 
Microsoft-HTTPAPI/2.0
Transfer-Encoding: 
chunked
X-AspNet-Version: 
2.0.50727
X-Powered-By: 
CData API Server

I went ahead and did some debugging based on the error that I'm receiving in the console and found the issue in the following place:

resources/sap/ui/model/odata/v4/lib/_Requestor-dbg.js

	Requestor.prototype.doCheckVersionHeader = function (fnGetHeader, sResourcePath,bVersionOptional) {
		var sODataVersion = fnGetHeader("OData-Version"),
			vDataServiceVersion = !sODataVersion && fnGetHeader("DataServiceVersion");
		if (vDataServiceVersion) {
			throw new Error("Expected 'OData-Version' header with value '4.0' but received"
				+ " 'DataServiceVersion' header with value '" + vDataServiceVersion
				+ "' in response for " + this.sServiceUrl + sResourcePath);
		}
		if (sODataVersion === "4.0" || !sODataVersion && bVersionOptional) {
			return;
		}
		throw new Error("Expected 'OData-Version' header with value '4.0' but received value '"
			+ sODataVersion + "' in response for " + this.sServiceUrl + sResourcePath);
	};

This is function that's throwing the error.

Is there any setting to disable this check or to force the framework to accept that the response is in-fact V4 ODATA?

Please help me resolving this.

View Entire Topic
0 Kudos

Hi,

The same issue happened to me, and finally I have solved it. I just write down the solution here to hope it can help others.

in my situation, it caused by CORS.

background:

During a CORS request, the getResponseHeader() method can only access simple response headers. Simple response headers are defined as follows:

  • Cache-Control
  • Content-Language
  • Content-Type
  • Expires
  • Last-Modified
  • Pragma

That's why you can't get "OData-Version" field.

Solution:

Turn off CORS check at browser level.

  1. Create a shortcut on your desktop
  2. Right-click on the shortcut and click Properties
  3. Edit the Target property
  4. Set it to "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="C:/ChromeDevSession"
  5. Start chrome and ignore the message that says --disable-web-security is not supported!

BEWARE NOT TO USE THIS PARTICULAR BROWSER INSTANCE FOR BROWSING BECAUSE YOU CAN BE HACKED WITH IT!