Finally decided this. To invoke a maintenance operation on a data service class, you need to use the methods of the CreateQuery or Execute data context object. For example:
ProductDataService ctx = new ProductDataService( new Uri("http://localhost:1234/ProductDataService.svc/")); // Method 1: DataServiceQuery<Product> q = ctx.CreateQuery<Product>("GetProducts"); List<Product> products = q.Execute().ToList(); // Method 2: Uri uri = new Uri(String.Format("{0}GetProducts", ctx.BaseUri), UriKind.RelativeOrAbsolute); List<Product> products = ctx.Execute<Product>(uri).ToList();
If you need parameters, let's say a product category in a service operation that had this signature:
[WebGet] public IQueryable<Product> GetProducts(string category)
We would do:
// Method 1: DataServiceQuery<Product> q = ctx.CreateQuery<Product>("GetProducts") .AddQueryOption("category", "Boats") ; List<Product> products = q.Execute().ToList(); // Method 2: Uri uri = new Uri(String.Format("{0}GetProducts?category={1}", ctx.BaseUri, "Boats"), UriKind.RelativeOrAbsolute); List<Product> products = ctx.Execute<Product>(uri).ToList();
Kev
source share