Salakhetdinov Shamil
mcp2004 at mail.ru
Thu May 3 13:51:25 CDT 2012
Hi All -- BTW, here is a fully dynamic (/"extra" late bound) sample oData web service client call - for the ones who likes such a level of risk/dynamism :) using System; using System.Linq; using System.Data.Services.Client; namespace ConsoleApplication1 { public class DataModelProxy : DataServiceContext { public DataModelProxy(Uri serviceRoot) : base(serviceRoot) {} public IQueryable<dynamic> EmployeesList { get { return CreateQuery<dynamic>("Employees"); } } //public IQueryable<TestService.Employee> StronglyTypedEmployeesList //{ // get { return CreateQuery<TestService.Employee>("Employees"); } //} } class Program { static void Main(string[] args) { var proxy = new DataModelProxy(new Uri(@"http://services.odata.org/Northwind/Northwind.svc/")); //var employees = from e in proxy.StronglyTypedEmployeesList where e.Title.StartsWith("Sales") orderby e.LastName select e; var employees = from e in ((proxy.EmployeesList).ToList()) where e.Title.StartsWith("Sales") orderby e.LastName select e; foreach (var e in employees) { Console.WriteLine("{0}. {1} {2} - {3}", e.EmployeeID, e.LastName, e.FirstName, e.Title); } } } } Thank you -- Shamil Thu, 03 May 2012 17:10:02 +0400 от Salakhetdinov Shamil <mcp2004 at mail.ru>: > Hi Gustav at all -- > > Just wanted to finish my first try of oData web services consumption on positive note and applied KISS-principle by writing a tiny oData client app - and I have got some progress here in consuming sample oData (?) service from Chris Sells article: > > http://services.odata.org/Northwind/Northwind.svc > > You can do the same - just: > > 1. Create VS2010 console application project - ConsoleApplication1 > 2. Add Service Reference to http://services.odata.org/Northwind/Northwind.svc and call it TestService > 3. Copy & paste, compile, build, and run code from P.S. of this message - and you'll get the following test output: > > 5. Buchanan Steven - Sales Manager > 1. Davolio Nancy - Sales Representative > 9. Dodsworth Anne - Sales Representative > 7. King Robert - Sales Representative > 3. Leverling Janet - Sales Representative > 4. Peacock Margaret - Sales Representative > 6. Suyama Michael - Sales Representative > > Easy? Yes, it's. > > .NET 'magic' makes all the dirty work for you to parse web query ATOM result of > > http://services.odata.org/Northwind/Northwind.svc/Employees > (try it in a web browser) > > into the above test output. > > Question to Francisco: does ObjectiveC have similar high level ATOM feeds consuming libraries and tools to generate strongly typed client APIs? (I should have I guess...) > > Thank you. > > -- Shamil > > P.S. > > using System; > using System.Linq; > using System.Data.Services.Client; > > namespace ConsoleApplication1 > { > public class DataModelProxy : DataServiceContext > { > public DataModelProxy(Uri serviceRoot) : base(serviceRoot) {} > > public IQueryable<dynamic> EmployeesList > { > get { return CreateQuery<dynamic>("Employees"); } > } > > public IQueryable<ConsoleApplication1.TestService.Employee> StronglyTypedEmployeesList > { > get { return CreateQuery<ConsoleApplication1.TestService.Employee>("Employees"); } > } > } > > class Program > { > static void Main(string[] args) > { > var proxy = new DataModelProxy(new Uri(@"http://services.odata.org/Northwind/Northwind.svc/")); > > //var employees = from e in proxy.EmployeesList select e; > var employees = from e in proxy.StronglyTypedEmployeesList where e.Title.StartsWith("Sales") orderby e.LastName select e; > > foreach (var e in employees) > { > Console.WriteLine("{0}. {1} {2} - {3}", e.EmployeeID, e.LastName, e.FirstName, e.Title); > } > } > } > } > > > <<< skip >>>