Breeze.js with WCF Data Service

烈酒焚心 提交于 2019-12-06 07:05:44

问题


I just started exploring the js library, breeze.js. I've looked through the samples but can't seem to find any example on how to consume a WCF Data Service (all the examples seem to be on Web API).

Does any one know how to consume a WCF Data Service (or any other OData service) with breeze.js?

I read somewhere in the docs that breeze.js only supports reads for OData services at the moment. That is fine by me as the use-case I'm considering it for does not include writes to the OData Service.


回答1:


The configuration described in this answer is no longer correct!

I am one of the engineers on Breeze.

The simplest way to talk to an OData service with Breeze is to first configure breeze to talk to OData.

breeze.core.config.setProperties({
    // the OData provider
    remoteAccessImplementation: entityModel.remoteAccess_odata;
    // this is the Knockout provider but we also provide a Backbone provider
    //  and we have others on the way
    trackingImplementation: entityModel.entityTracking_ko,
});

and then initialize an EntityManager and make your first query.

var myServiceName = "http://localhost:9009/ODataService.svc";
var em = new breeze.entityModel.EntityManager( {serviceName: myServiceName });

var query = breeze.entityModel.EntityQuery.from("Customers")
    .where("CompanyName", "startsWith", "B")
    .orderBy("City");

em.executeQuery(query).then(function(data) {
   // process the results here.
});

You should be able to consume any OData service in this manner.

The Breeze docs at http://www.breezejs.com/documentation/introduction can provide a great deal more information.

Also, please let us know what it was that made you feel that JayData was a better fit. This is how we improve our product.

thanks




回答2:


Corrected OData configuration and example

Jay's answer appears to be substantially out of date. I do not believe that any trace remains in Breeze of the entityModel type that appears in that answer. The following snippet from that answer will fail:

entityModel.remoteAccess_odata // does not work!

Do This!

As I write, the recommended way to configure Breeze so that it talks to a standard OData source (such as a WCF OData service) is

breeze.config.initializeAdapterInstance('dataService', 'OData', true);

The balance of Jay's answer needs a slight correction to remove the reference to entityModel:

// specify the absolute URL to the WCF service address
var serviceName = "http://localhost:9009/ODataService.svc";

var em = new breeze.EntityManager(serviceName );

var query = breeze.EntityQuery.from("Customers")
    .where("CompanyName", "startsWith", "B")
    .orderBy("City");

em.executeQuery(query).then(function(data) {
   // process the data.results here.
});


来源:https://stackoverflow.com/questions/13135215/breeze-js-with-wcf-data-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!