1
votes

I am just getting started with using Wcf Data Services to expose an entity framework database. I am quite familiar with WCF in general but not with data services.

I am trying to create a client without having to run the program and add a service reference.

This is because the database is not created, or complete, and there are other developers working on this.

I have looked at using the DataService<T>.AttachHost() method however this requires a IDataServiceHost which apparently DataServiceHost does not implement.

Does any one know a way to achieve this, or am I stuck with add service reference.

Thanks

EDIT

Just to explain a little more, as on reflection my question was poorly phrased.

Here is an example of the network setup

SQL SERVER | Firewall | APP SERVER | Firewall | CLIENTS

So there is a database on the SQL SERVER (MS-SQL)

The WcfDataService is running on the APP SERVER on port 1234. WcfDataService implemented by inheriting from DataService<MyContext> and hosting in a windows service

The clients need to connect to the DataService, using endpoint something like - htp://app-server:123465/

How can I create a class, preferably with an associated interface so I can unit test which would connect to the DataService and use its methods.

Thanks

1
You can use the DataSvcUtil.exe tool to generate the code files from an entity model without having the service hosted anywhere. See msdn.microsoft.com/en-us/library/dd756369%28v=vs.110%29.aspx for more info. - ChrisO
Should have stated that we use code first, so the entites are POCO and there is a DbContext. Is this method possible with this setup, as I am not sure what a .csdl file is? - Nick Williams
The .csdl file is just the metadata file that is exposed when the service is hosted, it's a representation of your entity model. Add Service Reference uses that file to generate the client side DataServiceContext code. I searched for quite a while and haven't found a way to generate the DataServiceContext code from a code first model. - ChrisO
You might have some luck looking into the t4 templates released by the odata team a while ago, it's possible they could be adjusted for your needs: blogs.msdn.com/b/astoriateam/archive/2012/07/02/… - ChrisO
Thanks ChrisO I will look into T4, I have updated the question just in case anything wasn't clear. - Nick Williams

1 Answers

0
votes

It sounds like you are just asking how to create the client context. You can use DataServiceContext.

Example:

var serviceRoot = new Uri("http://app-server:123465/");
var context = new DataServiceContext(serviceRoot, DataServiceProtocolVersion.V3);

** There is more work beyond this... but this should get you started down the right path.