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,389

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.

Accepted Solutions (0)

Answers (5)

Answers (5)

Hi,

please make sure the response headers of your odata service includes the header "Access-Control-Expose-Headers" to include all relevant headers, or at least "OData-Version". Otherwise, the jQuery won't be able to access theses headers.


See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers and https://stackoverflow.com/questions/14686769/xmlhttp-getresponseheader-not-working-for-cors

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!

0 Kudos

Hey,

i Debugging a littlebit my i found a Problem. The Header must be speratet by semicolon.

My header it looks like this;

mPredefinedRequestHeaders: {Accept: "application/json;odata.metadata=minimal;IEEE754Compatible=true", OData-MaxVersion: "4.0", OData-Version: "4.0", X-CSRF-Token: "Fetch"}

Maybe you have the same Problem.


0 Kudos

Hi Mathias

Thanks for the response.

The service request is not a batch request but a single request. The response-headers are also from the same request. Please check the screen-shot.

MathiasUhlmann
Advisor
Advisor
0 Kudos

Hi Ravikiran,

the OData V4 specification specifies "OData services MUST include the OData-Version header on a response to specify the version of the protocol used to generate the response. The client MUST interpret the response according to the rules defined in the specified version of the protocol.", cf.

http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-.... So it would be the server that needs to ensure that it is spec-compliant and sends the OData version.

Your response header seems to contain the correct "OData-Version: 4.0" but this did obviously not arrive in the coding. Do you use batch requests? Is the header you quote the response header of the batch request? How about the individual requests within the batch? Is the "OData-Version" also sent back there?

Best regards
Mathias.