3
votes

Breeze is calling the "fail()" function, even though the data seems to be returned from the odata service (as well as being in the error object). There are 5 "transactions" returned from the ODATA service (as seen in Chrome developer tools) as well as in the "data" property of the error object being passed to the fail function.

Calling code looks like this:

    function getTransactions() {
        var query = breeze.EntityQuery.from("Transactions")
                        .take(5);

        return entityManager.executeQuery(query,
            function(data) {
                log("transaction Query success!");
                var transactions = data.results;
            },
            function(err) {
                log("Query failed:" + err.message);
            });
    }

I am at a loss as to what is wrong that is causing the "fail()."

There IS a Transaction constructor defined, code below:

   function registerTransactions(metadataStore) {
        metadataStore.registerEntityTypeCtor('Transaction', Transaction);

        // constructor -- empty
        function Transaction() { };

        Object.defineProperty(Transaction.prototype, 'itemCount', {
            get: function () {
                return 0;
            }
        });
    }

Note the url for the odata resource is "Transactions" but the entity is Transaction. What are the reasons why the "Fail() function would be called?

Error.message = "; " which isn't helping much.

I believe I am on the latest Breeze 1.4.11 and datajs 1.1.2

1
Note: I removed the transaction constructor without impact. Also, I created a whole new service (the same, asp.net odata) and a new controller, with different entities and still the same problem. I get back data in the response but the fail function is called with no error message. - pinnprophead
Please show your breeze configuration ... in particular what "dataService" adapter you chose and what URL you're calling. Please also be specific about the OData service you're talking to. Is it an ASP.NET Web API 2 OData service? A WCF OData service? I'm fearful that DataJS is causing you the pain ... and that means walking your way through it until you see where it's dying (and hiding the failure). - Ward
I was suspecting datajs too -- My only breeze configuration is: - pinnprophead
breeze.config.initializeAdapterInstances({ dataService: "odata" }); I am using asp.net webapi 2.1 (says v5.1.2) ASP.NET Odata service 2.1 (Says 5.1.2). url is : localhost:49858/odata As I mentioned, it is coming back with the correct data -- one call to the $metadata and then to the resource url (odata/transactions) which looks good. Thanks Ward! - pinnprophead
If you want $batch support, consider the "webApiOData" adapter instead of the "odata" adapter. - Ward

1 Answers

3
votes

After much research, I found the problem was another funcky CORS setting on the service side. I was able to figure it out by going directly to dataJS against the same service, and getting a more informative error message.

What you MUST do on the service side is something like this:

var cors = new EnableCorsAttribute("*", "*", "*", "DataServiceVersion, MaxDataServiceVersion");

The last parameter has to with the service sending the OData version in the header and thereby allowing the client to determine if it can handle the specified version of OData.

If anyone knows more details about this, feel free to comment.