ADO.NET Data Services Services from a .NET Client

I am trying to create an ADO.NET data service with a large number of objects and several maintenance operations. On the one hand, I created an ASP.NET web application that hosts the ADO.NET Entity Data Model and ADO.NET Data Service. On the other hand, I created a second ASP.NET web application that has a link to a data service service.

The entities go very well, I can use LINQ to get the required data:

TestEntities entities = new TestEntities( new Uri("http://localhost/service/service.svc")); var query = from customer in entities.Customers where customer.ID == 1234 select customer; query.ToList(); 

It works. However, getting information through Service Operations completely eludes me. Data Service Code:

 public static void InitializeService(IDataServiceConfiguration config) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); } [WebInvoke] public IQueryable<Customer> GetSomeCustomers() { TestEntities entities = new TestEntities(); return from customer in entities.Customers where customer.ID > 0 && customer.ID < 20 select customer; } 

When I added the service link to my client's project, Visual Studio did not pick up any service operations. I know that I can access them through the constructed URIs and the BeginExecute method of the DataServiceContext object or the TestEntities object (in this case) or something like that, but this is not how I want it.

What I want is to use LINQ to view the returned Service Operation data. Is it possible? Should it be right?

+4
source share
1 answer

Simple things as soon as you know.

A few things to know:

Currently, DataServiceClientGenerator (which uses EntityClassGenerator) does not create methods for utility operations.

Using the CreateQuery method in the context is not supported for official operations, they currently work because there is no client-side validation for this (you will notice that if you use CreateQuery, a "()" is added to the end of the request method like this http : //localhost/service.svc/method ()? parameter = 2 ", you can use CreateQuery, but this is not recommended.

Not all utility operations return values, but for this example I will show only an example for those that do.

 public partial class NorthwindEntities { public IQueryable<Order> OrdersByRegion(int regionId) { return this.Execute<Orders>(new Uri(string.Format("{0}OrdersByCountry?regionId={1}", this.BaseUri, regionId), UriKind.RelativeOrAbsolute)); } } 

If you need more information, you can ask any questions.

PS: In your example, you do not need to create a new data context in your service (on the server side), the DataService already has a link created when the service was called.

In fact, you can override the creation of a data context on the service side as follows:

 protected override NorthwindEntities CreateDataSource() { return new NorthwindEntities(); } 
+5
source

All Articles