3

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

pinnprophead
  • 215
  • 3
  • 14
  • 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 May 01 '14 at 12:28
  • 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 May 02 '14 at 03:07
  • I was suspecting datajs too -- My only breeze configuration is: – pinnprophead May 02 '14 at 21:57
  • 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 : http://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 May 02 '14 at 22:06
  • If you want $batch support, consider the "webApiOData" adapter instead of the "odata" adapter. – Ward May 03 '14 at 01:53

1 Answers1

3

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.

Community
  • 1
  • 1
pinnprophead
  • 215
  • 3
  • 14