0

The Short

I have an existing WCF Data Service that I would like to wire up to use in an AngularJS SPA using Breeze.

Can anyone show a noobie level example of how to do that with out access to the actual database (just the OData Service)?


The Long

I have an existing WCF Data Service that is already in use by a WPF app.

I experimenting with web development and would like to wire up to that service using Breeze. In case it matters, I am using Angular (and am setting up via the HotTowel.Angular nuget package).

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.

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. 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.


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.

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.


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. 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.

To to clearly summarize what I am asking: I am looking for a Breeze example that connects to an existing WCF Data Service.

Community
  • 1
  • 1
Vaccano
  • 78,325
  • 149
  • 468
  • 850
  • Is your WCF Data Service an OData service? Or is it an arbitrary WCF SOAP service? I ask because you mentioned that your WCF Data Service responds to url+$Metadata which makes it sound like a WCF OData Service. And if it is, how is the guidance for talking to a WCF OData service - the guidance to which you linked - letting you down? It should be as simple as picking the Breeze OData data service adapter and targeting the full WCF service URL. – Ward Apr 26 '14 at 01:43

1 Answers1

1

We regret that you were mislead by that old StackOverflow answer which was way out of date and (therefore) incorrect. There is no longer a type called 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.config.initializeAdapterInstance('dataService', 'OData', true);

Here's how you might proceed with defining an EntityManager and querying the service:

// 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. But you may still find value in the Angular Web API OData sample.

Ward
  • 17,793
  • 4
  • 37
  • 53
  • I am still trying to get this to work. If I do get it working, I will comeback and accept the answer. (Right now I am getting a `Unable to locate a 'Type' by the name: MyEntityHere` error. I am guessing it is not loading MetaData right.) – Vaccano Apr 28 '14 at 19:34
  • Does this code really work against an OData Service for you? When I try with my OData Endpoint I get a request to load the metadata. Which should be done automatically, but I have tried doing manually too. Anyway, I appreciate the response, but as is, something is missing. I cannot seem to get past that error. – Vaccano Apr 28 '14 at 23:39
  • Thank you Ward for the help! I had an issue with Breeze not liking my OData Metadata. See this answer if you are interested: http://stackoverflow.com/a/23371102/16241 – Vaccano Apr 29 '14 at 17:15
  • 1
    That's an **important catch** and much too common stumbling point when working with **WCF OData**. I need to make note of this in our documentation as the root cause is beyond our control. – Ward Apr 29 '14 at 21:16
  • Are you sure you mean Web API OData? I was using WCF OData and I had this problem. And the training by Brian that told me about this was specifically for WCF Data Services. I have not used Web API OData, so I can't say if it is also affected. But for me this was an issue with WCF Data Services (OData) that was fixed when I made the two values the same. – Vaccano Apr 30 '14 at 22:12
  • I don't think model namespace confusion is an issue with WCF OData. Why do you think it is? Brian's blog post, in which he refers to the setting of the namespace in "Step 4", is [quite clearly about ASP.NET Web API](http://briannoyes.net/2013/02/16/consuming-an-asp-net-web-api-odata-service-with-breeze/) OData, not WCF OData. So now you have me completely confused. Which technology are you actually using? – Ward May 02 '14 at 07:10
  • I am using WCF OData (WCF Data Services). This issue did happen for me in WCF Data Services. I thought that the example from Brian's Pluralsight video was for WCF Data Services. Maybe I was wrong, but it fixed my problem either way. – Vaccano May 02 '14 at 15:34