简体   繁体   English

将Breeze(使用Angular)连接到现有的WCF数据服务

[英]Wireing Breeze (with Angular) to an existing WCF Data Service

The Short 短小

I have an existing WCF Data Service that I would like to wire up to use in an AngularJS SPA using Breeze. 我有一个现有的WCF数据服务,我想将其连接到使用Breeze的AngularJS SPA中。

Can anyone show a noobie level example of how to do that with out access to the actual database (just the OData Service)? 谁能在不访问实际数据库 (仅是OData服务)的情况下,展示如何做到这一点的noobie级示例


The Long 长龙

I have an existing WCF Data Service that is already in use by a WPF app. 我有一个已由WPF应用程序使用的现有WCF数据服务。

I experimenting with web development and would like to wire up to that service using Breeze. 我正在尝试Web开发,并希望使用Breeze连接到该服务。 In case it matters, I am using Angular (and am setting up via the HotTowel.Angular nuget package). 如果很重要,我将使用Angular(并通过HotTowel.Angular nuget包进行设置)。

I have done a fair amount of Googling and I am stuck. 我做了很多谷歌搜索,但被卡住了。

I can see two ways outlined from my searching: 我可以从搜索中看到两种方式:


The First 首先

Make is to make a Breeze controller on the server side of my web app. Make是在Web应用程序的服务器端制作Breeze控制器。

The problem I see with that is the metadata. 我看到的问题是元数据。 From my limited understanding I need to tell breeze all the meta data of my WCF Data Service. 从我有限的理解出发,我需要告诉WCF数据服务的所有元数据。 I know how to get the meta from my WCF Data Service (the url + $Metadata), but I don't know how to tell this to Breeze. 我知道如何从WCF数据服务(URL + $ Metadata)中获取元数据,但是我不知道如何将此告知Breeze。


The Second 第二

This way is more vague in implementation. 这种方式在实现中更加模糊。 I got it from the accepted answer on this question: Breeze.js with WCF Data Service . 我是从以下问题的公认答案中获得的: 带有WCF Data Service的Breeze.js

Basically the answer here does not seem to work. 基本上,这里的答案似乎无效。 It relies on something called the entityModel that I cannot seem to find (I have an entityManager, but not an entityModel. And the entityManager does not have the properties that the entityModel is shown to have. 它依赖于我似乎找不到的称为entityModel东西(我有一个entityManager,但没有entityModel。而且entityManager不具有如图所示的entityModel所具有的属性。


In the end I like the idea of the second method best. 最后,我最喜欢第二种方法的想法。 That way I can directly connect to my odata service with out needed my web app to have a "in-between" server component. 这样,我可以直接连接到odata服务,而无需Web应用程序具有“中间”服务器组件。 But I would happily take anything that does not need entity framework to connect to my database. 但是我很乐意采用不需要实体框架连接到我的数据库的任何东西。

I tried several variations of the second option, but I just can't seem to get it to work. 我尝试了第二种选择的几种变体,但似乎无法正常工作。 I also tried the Breeze samples. 我还尝试了微风样品。 It has one for OData, but it still relies on having Entity Framework hook up to the source database. 它具有一个用于OData的数据库,但仍然依赖于将Entity Framework连接到源数据库。

To to clearly summarize what I am asking: I am looking for a Breeze example that connects to an existing WCF Data Service. 为了清楚地总结我的要求: 我正在寻找一个Breeze示例,该示例连接到现有的WCF数据服务。

We regret that you were mislead by that old StackOverflow answer which was way out of date and (therefore) incorrect . 很遗憾,您被旧的StackOverflow答案误导了,该答案已经过时并且(因此)不正确 There is no longer a type called entityModel . 不再有一个称为entityModel的类型。

I updated the answer there and repeat here the same advice. 我在那里更新了答案,并在这里重复了同样的建议。

The recommended way to configure Breeze so that it talks to a standard OData source (such as a WCF OData service) is 推荐的配置Breeze使其与标准OData源(例如WCF OData服务)对话的方法是

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

Here's how you might proceed with defining an EntityManager and querying the service: 以下是定义EntityManager并查询服务的方法:

// 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.
});

There is some documentation on this subject here . 有关于这个问题的一些文件在这里

A Web API OData service differs from a WCF OData service in several respects. Web API OData服务在几个方面与WCF OData服务不同。 But you may still find value in the Angular Web API OData sample . 但是,您仍然可以在Angular Web API OData示例中找到价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM