Error No Handler for Data

Sep 3, 2013 at 10:49 AM
Edited Sep 3, 2013 at 10:49 AM
I've seen this error reported a few times already but the cause seems to be always different.

I'm trying to access a WEBAPI OData service and while I do get results (I see that from the response in Chrome), the error 'No Handler for Data' is raised by datajs.

The Response Body contains the data in JSON format

The Request Header is :
Demande GET /odata/Mandates?$inlinecount=allpages HTTP/1.1
MaxDataServiceVersion   3.0
Accept  application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
Referer http://localhost:1506/axa.portal.web/chat
Accept-Language fr-FR
Accept-Encoding gzip, deflate
User-Agent  Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Host    localhost:52446
Connection  Keep-Alive
and the Response header is:
Cache-Control   no-cache
Content-Length  22494
Content-Type    application/json; charset=utf-8
Date    Tue, 03 Sep 2013 09:40:30 GMT
Expires -1
Persistent-Auth true
Pragma  no-cache
Réponse HTTP/1.1 200 OK
Server  Microsoft-IIS/8.0
WWW-Authenticate    Negotiate oRswGaADCgEAoxIEEAEAAABDh+CIwTbjqQAAAAA=
X-AspNet-Version    4.0.30319
X-Powered-By    ASP.NET
X-SourceFiles   =?UTF-8?B?YzpcdXNlcnNcYmVydGhlbG90c1xkb2N1bWVudHNcdmlzdWFsIHN0dWRpbyAyMDEyXFByb2plY3RzXFdlYkFQSU5vQnJlZXplXFdlYkFQSU5vQnJlZXplXG9kYXRhXE1hbmRhdGVz?=
Dec 11, 2013 at 6:14 AM
Hello,

I have the same issue. The response from the service seems good but "No handler fort data" is raised by datajs. The success callback is never called.
Jan 28 at 11:24 PM
Hi,

I am also seeing this error and have no idea how to fix :/

I have setup a web api 2.1 oData service and can call it fine in the browser.

When trying to call using datajs however I get the No handler for data error and like the OP i can see the data being returned in Chrome. Here is my code calling the service:

    OData.read({
        requestUri: "http://localhost:81/odata/BlogPost",
        data: "json",
        method: "GET"
    },
    function (data) {
       alert(JSON.parse(data));
    },
    function (err) {
        alert(err.message);
    });
Here are the headers from chrome:

Request Header
GET /odata/BlogPost HTTP/1.1
Host: localhost:81
Connection: keep-alive
Cache-Control: no-cache
Pragma: no-cache
MaxDataServiceVersion: 3.0
Origin: http://localhost
User-Agent: Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36
Content-Type: application/json
Accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
DataServiceVersion: 1.0
DNT: 1
Referer: http://localhost/Blog
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,en-US;q=0.6
Response Headersview source
Response Header
Access-Control-Allow-Origin:http://localhost
Cache-Control:no-cache
Content-Length:4196
Content-Type:application/json; odata=fullmetadata; charset=utf-8
DataServiceVersion:3.0
Date:Tue, 28 Jan 2014 22:33:12 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Here is the data being returned.
{
  "odata.metadata":"http://localhost:81/odata/$metadata#BlogPost","value":[
    {
      "BlogPostID":1,"BlogPostTitle":"Welcome To Azert","BlogPostDate":"2014-01-07T22:38:17","BlogPostSummary":"<p>\r\n\tAzert is a Belfast, Northern Ireland based tech blog</p>\r\n","BlogPostBody":"Text here","BlogPostTeaser":null
    }
  ]
}
The headers etc seem to be fine, is it a problem with my data?

Mark
Jan 29 at 12:35 PM
Hi,
You might suffer from some missing CORS headers (on response) that prevent datajs from properly handling your data (hence the error message). I wrote a discussion part on it. Please see CORS with datajs 1.1.1 and OData v3 discussion.
Jan 29 at 1:18 PM
Hi,

This looks identical to my problem. I have actually already included CORS as I came across the same link you mention in your post (http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api).

My setup of it must be the problem I think, you mentioned in your post that:
It was configured to accept all origins, all headers, all methods on requests and exposed the OData specific headers on responses.
How did you set this up to expose the OData response headers?

Mine is currently setup like the below:
var cors = new EnableCorsAttribute("http://localhost", "*", "GET");
        config.EnableCors(cors);
Am I missing something here?

Mark
Jan 29 at 2:06 PM
Edited Jan 29 at 2:07 PM
Hi Mark,

The magic happens in the 4th parameter of the EnableCorsAttribute constructor:
config.EnableCors(new EnableCorsAttribute("*", "*", "*", "DataServiceVersion, MaxDataServiceVersion"));
In particular the DataServiceVersion header, being exposed on responses this way, is picked up by datajs when trying to handle the response.

Michael
Jan 29 at 2:51 PM
Ahhh, I see, didn't know about that!

I'm not at home at the moment but will be later and I'll be trying this out as soon as I get in. I'll let you know if I get any success!

Thanks,

Mark
Jan 29 at 11:21 PM
Hi,

It works! Thanks very much for your help!

Mark